I’m trying to make a nice dust effect when a player flies close to the ground. I’ve made a child object with a partile system on it on the player, that is activated “OnTriggerStay” and then I have a trigger-box close to the surface of the ground, because my ground is completely flat.
This works but I want the dust to stick to the ground and not elevate or descend on the Y-axis, only follow the player on the X and Z axis. Does anyone know a way to make this happen?
Here’s my code ( the boolean becomes true when the player is inside the trigger box, and if the boolean is true the particleFX turn on) :
bool aPlaning;
public GameObject FxPlaning;
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "GroundplaningBox")
{
aPlaning = true;
}
}
void FixedUpdate()
{
if (aPlaning)
{
FxPlaning.SetActive(true);
}
}
Sorry I wasn’t clear enough: The particle system works exactly as it should, but as a child object it follows the player when the player moves in any direction. I need the particles to show on the surface of the ground only and not follow the player on the Y-axis as the player flies up off the ground.
To explain it differently: I’m basically trying to make the dust/smoke effect from a hover-aircraft on the ground when the aircraft gets close. I can’t find any tutorials on it and it’s a bit of a head scratcher, because if I instantiate the dust on trigger enter, how can I still get it to follow the player who’s in the air while sticking to the ground? The dust/smoke effect particle system emitter should never leve 0 on the Y-axis. Same issue if the dust is a child object and not instantiated…
To know where the particles should be, and if they should be active, you trhow a ray from the hovercarft, downwards [ Physics-Raycast - Unity Scripting API ].
You can see the ray visually in the scene using Debug.DrawRay. You should check that you’re casting it in the right direction and lenght. The ray’s lenght should be equal to the maximum height in wich your hovercraft will produce smoke.
Every time the ray intersects with the floor, you know you should turn on the particles and adjust the particle system’s position to match the raycastHit position (the hit is the place where your ray hits the collider).
When you throw the ray, use a mask to only look for collisions with the layer of the floor. You can also avoid trhowing rays in cases you know it won’t hit the floor, and also check only every n frames when it’s off. When is on, though, you probably want it to throw the ray every frame so that the particle system follows your hovercraft properly. You can also adjust the particle system inclination to follow the slop of the terrain using the raycastHit.normal.