- Home /
How can i stop animals in may game overlap each other??
hey Folks, i know this has been asked previously but none of them helped me to sort out.. i have animals in my game on them i had rigidbody character controller and box collider too. but when they chase player they gets overlapp each other. i want them to stay way from each other. help thanks in advance..
How do you move your animals? Show the script. From what I understand, that's where you will have a problem. Do you really need rigid body on them? character controller + simple collider should be enough. Depending on the needs of course
@Gr$$anonymous$$l its quite large code and i am using character controller and simple box collider
Answer by HarshadK · Dec 02, 2014 at 12:30 PM
Then don't make it a trigger as rigidbodies can pass through trigger. Uncheck the Is Trigger checkbox and you're good to go.
But then they get stuck, grinding against each other. At best, you get one animal drifting sideways, sliding it's nose from shoulder to tail of another animal.
Better "avoidance" AI is the only thing I've found that works, but that's hard to write, and very specific.
What might kind of work is having small upright cylinder colliders. Would prevent them from the worst overlaps, and give an even slide-off for all by head-on collisions.
@saracecilia no this is not solved And @Harshadk when i does that the animals starts flying and that weird.. is there is any scripting ref or ideas???
@hgaur The animals might be flying because some external force is applied on them. Try increasing their mass.
Also try the method stated by @owen-reynolds in his comment.
Answer by screenname_taken · Dec 03, 2014 at 12:18 PM
The way i did it in mine is really crude, but for my case it helped. I assigned each animal an integer, and that integer showed its order in importance if you like. Then i made a function for OnTriggerEnter, to check that integer on the collider that entered that trigger. If the incoming trigger is of higher value than its own, then it has to give way. Basically reduce its movement speed or turn around. It doesn't work for a lot of animals together, but for a couple it helps. Perhaps you'll get some ideas out of this, like changing it to work with raycasting so that the enemy will know from advance that it needs to go around.
Your answer
Follow this Question
Related Questions
Checking if object intersects? 1 Answer
Not all sides of a cube collide properly( with pic) 2 Answers
Rigidbodies not working correctly 1 Answer