enemy using "isKinematic" stacks

Hi everyone,

I’m coding a script in C#. I’m building a tower defense and I’m having a huge issue here. My enemies spawn from a spawnpoint and goes all their way to where they are supposed to go.
When they get there, actually, I have to make them “stop”. So I’m using the “isKinematic” option coming with the rigidBody.

But my enemies stacks one atop the other. I’d need them to mass around, but stay put in y, only move in x.

Any solution anyone? Time grows short…

Hard to help as it is a big topic, and very little information to go on.

Suggest you read up on path finding and crowd simulation. There is a good video about it here FPS1.37 AI Pathfinding Crowd Simulation. Unity3D FPS Game Design Tutorial. - YouTube

If in the Editor you can just uncheck IsKinematic and just use the Rigidbody constraints, tick the position and rotation axes you want to restrict.

More specifically in code (c#), you can change the Rigidbody constraints with something like the following.

// To constrain the Y-axis position
private RigidbodyConstraints ConstrainYmovement;

ConstrainYmovement = RigidbodyConstraints.FreezePositionY; 

//and when setting it to your Rigidbody.

transform.rigidbody.constraints = ConstrainYmovement;

// Set back to default (no constraints)
private RigidbodyConstraints DefaultContriants = RigidbodyConstraints.None;

transform.rigidbody.constraints = DefaultContriants;

Hope that helps.