how can i make this object move? please help me guys.. :)

how can i made my object move forward once i press “w”?? also i would like to make my object turned left and right once i press “a” and “d”… Please help me guys… :slight_smile:

here’s my code…

function Update ()
{
//forward movement
if(Input.GetKey(“w”))
animation.CrossFade(“run”);
animation[“run”].wrapMode= WrapMode.Loop;

if(Input.GetKeyUp (“w”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;

//left movement
if (Input.GetKey(“a”) )
animation.CrossFade (“left”);
animation[“left”].wrapMode = WrapMode.Loop;

if(Input.GetKeyUp (“a”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;

//right movement
if (Input.GetKey(“d”) )
animation.CrossFade (“right”);
animation[“right”].wrapMode = WrapMode.Loop;

if(Input.GetKeyUp (“d”))
animation.CrossFade (“idle”);
animation[“idle”].wrapMode = WrapMode.Once;

//reverse movement
if (Input.GetKey(“s”))
animation.CrossFade(“reverse”);
animation[“reverse”].wrapMode = WrapMode.Loop;

if(Input.GetKeyUp(“s”))
animation.CrossFade(“idle”);
animation[“idle”].wrapMode = WrapMode.Once;
}

So you don’t want ot use a character controller?
If not u can use

rigidbody.velocity = transform.forward*yourSspeed;

And for turning

transform.Rotate(0, -turnSpeed*Time.deltaTime, 0);

To turn the other direction just change the operator to + before turnSpeed.

Just insert the lines of code right in the button input blocks. :smile:

sir it doesn’t work… i put already put a character controller in my character component…

when i test the code it the unity say’s that
“MissingComponentException: There is no ‘Rigidbody’ attached to the “jeenanimations” game object, but a script is trying to access it.
You probably need to add a Rigidbody to the game object “jeenanimations”. Or your script needs to check if the component is attached before using it.”

which means you should add one

i remove the character controller and change it to a rigidbody but it’s have the same error… T_T

the same error and you added the rigidbody to the “jeenanimations” game object ?
that’s strange.

luckly i’ve already solved the problem… i change the rigidbody to character controller with other code… :slight_smile: thanks you sir… :slight_smile: