Little dust particles after player jump hitting ground
I'm searching for info that does the following:
After the player character hits the ground some little dust particles will be instantiated, but these particles must stay on the spot he justed landed so they wont follow the player when he walks on.
I found some older solutions but they don't seem to work anymore. Can anyone help me in the right direction?
Answer by ASPePeX · Feb 13, 2017 at 08:46 AM
Instantiate() a ParticleSystem at the position he jumps off/lands and don't make the player its parent. Good practice is to Destroy() it after it has done its job.
Answer by Jojoba007 · Feb 13, 2017 at 08:53 AM
@ASPePeX Thanks for your reply, I got the instantiate working, now I still need to spawn it at the location where he lands? There is a OnTriggerEnter on the location where he lands, but how do I get the location of his feet hitting the ground?
Something like this?
GameObject dustObject = Instantiate(dustPuff, this.transform.position, this.transform.rotation) as GameObject;
The easiest way to do this is to just take a fixed offset of the position of your player character. There are other possibilities like using Collision.contacts but that comes with its own set of problems.
I got it working, thanks for sending me in the right direction:
This is the code, as simple as it can be ;-)
At the top a variable for the ParticleSystem and the GameObject followed by the code wherever in which function you want to call it:
public GameObject dustPuff;
private ParticleSystem dustParticle;
//Instantiate the dust particles when landing after a jump
GameObject dustObject = Instantiate(dustPuff, this.transform.position, this.transform.rotation) as GameObject;
dustParticle = dustObject.GetComponent<ParticleSystem>();