- Home /
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...
$$anonymous$$aybe try making their colliders really talk so they cant shift above one another?
Works for the first one, but every enemy following still stacks...
Answer by Linus · Jul 04, 2012 at 05:19 AM
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 http://www.youtube.com/watch?v=0nQnbxCiWWE
Answer by asimov · Jul 04, 2012 at 12:23 AM
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.