- Home /
If my object moves -- Detect on carachter controller?
I'm making a multiplayer stylish game with humanoid carachters and im using mecanim now, so I have a character controler on my carachter and how do I change if rigitbody moves to for example if object or transform etc moves here's the script
#pragma strict
internal var animator : Animator;
function Start ()
{
animator = GetComponent("Animator");
}
function Update ()
{
if (rigidbody.velocity != Vector3.zero) //Here it is
{
animator.SetBool("IsMoving",true);
}
else
{
animator.SetBool("IsMoving",false);
}
}
typically with character controllers you do not put a rigidbody on it. if you do it can sometimes make weird things happen.
If you are driving your characters with mecanim you will most likely end up creating a "speed" float in your animator to adjust his movement. After you set that up, detecting if the player is moving is as simple as
if(anim.GetFloat("speed") > 0.1){
moving = true;
}else{
moving = false
}
There are many ways to set up a animator controller. After a quick youtube search I found this tutorial you may find useful.
Your answer
Follow this Question
Related Questions
Changing 1 parameter of rigidbody.velocity (Vector3) 2 Answers
Can't access the velocity of a rigidbody: 'Rigidbody' does not contain a definition for 'velocity' 1 Answer
How do I get one object to point toward another using rigidbody physics? 2 Answers
How would I continue an object's movement in the same direction as per last user input? 1 Answer
What is wrong with this rigidbody? 2 Answers