Spawn a Particle with Raycast Hit Point / C++ Code

#1
Hi ,
How I can Spawn a Particle with Raycast hit point?
I use this code , when F key pressed , I want spawn a particle at Hit.Point but does not work!

Code: Select all

IParticleEffect* pEffect = gEnv->pParticleManager->FindEffect("fire.pfx"); if (pEffect) { pEffect->Spawn(IParticleEffect::ParticleLoc(hit.pt)); }
I Know , this code but do not have position :-( I searched a lot , I found nothing!!!

Code: Select all

ppe = gEnv->pParticleManager->FindEffect("fire.pfx"); GetEntity()->LoadParticleEmitter(0, ppe);
I do not want make a new class like bullet / projectile /SAM Rocket , etc

here is a way for game play programmers?

Please help me

thank you

Spawn a Particle with Raycast Hit Point / C++ Code

#2
Also , I Used old system (Database view-Particles tab) for make a particle but does not work again :-(
I used this code , but does not work , bo ho ho :-(

Code: Select all

string effect = "Level.fire.fire01"; IParticleEffect* pParticleEffect = gEnv->pParticleManager->FindEffect(effect); if (pParticleEffect) { Matrix34 effectPos; effectPos.SetIdentity(); effectPos.SetTranslation(hit.pt); // also for Spawn(true, effectPos) does not wok!!! IParticleEmitter* pEffect = pParticleEffect->Spawn(false, effectPos); }

Re: Spawn a Particle with Raycast Hit Point / C++ Code

#7
Hello,

I don't know what exactly is wrong with your setup, but you could have a look at the default particle component https://github.com/CRYTEK/CRYENGINE/blo ... omponent.h. If that doesn't help, it might be helpful to post your code so I can have a look.

Cheers,
Alex
Thank you Dear Alex , I saw this header , Also I tested a new c++ code , please see my code :

Code: Select all

void CPlayerComponent::SpawnParticleSystemHit(ray_hit hit) { IParticleEffect* pEffect = gEnv->pParticleManager->FindEffect("fire.pfx"); also I test -->> //("Level.fire.fire01"); if (pEffect == nullptr) CryLog("null ptr :-< bo ho ho 1"); if (pEffect == NULL) CryLog("null ptr :-< bo ho ho 2"); if (pEffect) { SEntitySpawnParams hitparam; hitparam.vPosition = hit.pt; //GetEntity()->GetPos(); hitparam.vScale = Vec3(1.f, 1.f, 1.f); IParticleEmitter* iemiter = pEffect->Spawn(hitparam.vPosition); // also I tested -->> IParticleEffect::ParticleLoc(hit.pt) CryLog(cstr(pEffect->GetName())); CryLog("SPS :-> x:" + ToString(hit.pt.x) + " y:" + ToString(hit.pt.y) + " z:" + ToString(hit.pt.z) + " Enshaallah..."); } }
But Does not work Again :-(

I see pEffect is not Empty and access to fire.pfx or old system particle , also I added this header :

Code: Select all

#include <CryParticleSystem\IParticlesPfx2.h> #include <CryParticleSystem\IParticles.h>
I tested hit.pt
hit.point is value correct related to hit position.

is a way without make a new component or without a new class , I spawn my particle?

Re: Spawn a Particle with Raycast Hit Point / C++ Code

#9
You can use component.. you don't have to create it.. It's extremely simple to attach ParticleComponent. But if you really don't want to do it, I recommend you to do that:

1.In Player.h create variable:

Code: Select all

IEntity *pParticleEntity = nullptr;
2.In your .cpp file(I assume you know how to do the raycast properly), create your method:

Code: Select all

void CPlayerComponent::SpawnParticleSystemHit(ray_hit hit)
{
if (IParticleEffect *pEffect = gEnv->pParticleManager->FindEffect(sName, "Particles"))
{
if (!pParticleEntity)
{
SEntitySpawnParams spawn;
spawn.pClass = gEnv->pEntitySystem->GetClassRegistry()->GetDefaultClass();
pParticleEntity = gEnv->pEntitySystem->SpawnEntity(spawn);
}
if (pParticleEntity)
{
pParticleEntity->SetPos(hit.pt);
pParticleEntity->FreeSlot(0);
pParticleEntity->LoadParticleEmitter(0, pEffect);
}
}
}
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20

Who is online

Users browsing this forum: No registered users and 1 guest

cron