Can Rigidbody be used in place of casting rays for keeping a game object walking on top of uneven terrain? I'm just playing with it and it seems to be ok, the only problem so far is that my soldier now will topple over trying to go up a hill :). That makes sense to me since his underlying collision object is a box.
So my question is if there is a way to force a rigidbody to always stay in an upright position? I'm guessing there must be some way to override the physics engines updates to my object right? Or is there a way to assign 99% of a gameobjects weight/mass to the bottom of the object (i.e. feet) so that it will not be impacted by slopes etc?
To be specific, what I'm asking is how to lock this object into staying parallel with the world Y axis instead of perpendicular to the surface slope and to effectively behave in a IsKinemetic with regards to balance/angles - while not being IsKinemetic (which would mean having to cast rays and adjust y axis every movement it looks like to "stay grounded").
Yes there is a method to stop your rigidbody toppling over. You can set the "Freeze Rotation" property, either in the rigidbody's inspector values, or via scripting.
You can then manually rotate the object around the Y axis using Transform.rotate, and you can rely on the object remaining upright at all times.
I was looking at this the other night and decided on something which is pretty obvious to me now :) :
Get the Vector3 that you want to travel to
Modify the Y-axis so that it is the SAME as the object you are moving.
LookAt the modified Vector3 instead of the original.
Now when you LookAt, it will of course look at the x,z coordinates and keep the same y as the current object which effectively keeps the object upright in its current context.
You can't use Transform.rotate or Transform.translate if used Rigidbody.
http://unity3d.com/support/documentation/Components/class-Rigidbody.html
You can use Rigidbody.MovePosition or Rigidbody.MoveRotation, but better to use Rigidbody.AddRelativeForce or Rigidbody.AddRelativeTorque for right work physics. And only into FixedUpdate().
Code for correction needless Rigidbody roration:
Quaternion rot = rigidbody.rotation;
rot[0] = 0; //null rotation X
rot[2] = 0; //null rotation Z
rigidbody.rotation = rot;