Make sheep stop rolling wildly

Hey there,

I’m working on a game where the main mechanic is punching sheep. We’re trying to get sheep to behave realistically when punched. Currently there’s a rigidbody attached to each sheep and a box collider (mesh collider was too expensive with 10+ sheep running around each level). The sheep is set to run around on its own.

If the sheep gets knocked over from being punched, that should be fine, but when the sheep is just running around the level sometimes it will randomly fall on its side (if it goes up a hill in the terrain or something) and be unable to get back up. Sometimes it just rolls around.

  1. What is the “best” way to make the sheep right itself automatically unless it’s been punched?

  2. Is there a way to automatically check if an object is above the terrain and apply gravity selectively? I noticed if gravity is turned off it doesn’t roll, but in that case when the sheep is punched it just floats in the air.

What do your punches consist of? If it’s a collider hitting the sheep, you can turn off isKinematic when a punch connects.

In UnityScript (placed on the sheep):

function OnCollisionEnter(collision : Collision) {
   rigidbody.isKinematic = false;
}

Edit: Or more elaborate, how about adjusting the center of mass for each sheep depending on their x and z rotations?

How many sheep are you looking at having in the scene? 10/20/30+

Something that may work for a lower number would be to apply a constant force to each sheep rather than global gravity.

By un-checking the Use Gravity option on your sheeps’ rigidbody and attaching a Constant Force component, you can toggle when (or when not) to apply gravity to the object.

Our punches consist of applying the ExplosiveForce function to the rigidbody. We are looking at probably having 15~ sheep in a level. Only 3-4 in the intro levels.

A combination of these two methods worked. At first I turned off isKinematic selectively and that worked, but the sheep have a second script on them which automatically rights them to the terrain so they “run” properly. The two scripts were fighting for control. Then I tried Alastair’s suggestion and attached a constant force to them, which made them seem a lot happier and glitch out less. :slight_smile:

Thanks!!

Glad you got a solution!

I’d love to see more of your project as it develops… I bust into laughter when I saw the forum post and even more when you described the game play!

Sounds like great fun!

Yeah, I think that

is the best line I’ve read all morning.

I think real sheep can get stranded on their backs and unable to get back up again sometimes so it probably adds a degree of realism!