- Home /
Help understand moveDirection = transform.TransformDirection(moveDirection);
var speed:float=10.0;
var controller:CharacterController=GetComponent(CharacterController);
moveDirection=Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
From code above:
It seem lines 3 and 4 have same job, assign value to Vector3, so why we add line 4?
Answer by fafase · Dec 14, 2012 at 08:11 AM
var speed:float=10.0;
this one is the speed you got it
var controller:CharacterController=GetComponent(CharacterController);
this one fetches the CharacterController component and should be put in the Start function
moveDirection=Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
this one gets the input and stores it in moveDirection
moveDirection = transform.TransformDirection(moveDirection);
This one converts moveDirection(the input) from local to world space and stores it in moveDirection
moveDirection *= speed;
this one multiplies moveDirection by the speed
controller.Move(moveDirection * Time.deltaTime);
And finally the vector is passed to the character controller with the Move function.
Your answer

Follow this Question
Related Questions
How to check in which direction an object is facing? 2 Answers
How do I include the transform direction when changing move direction? 1 Answer
how to set the rotation of a game object around the world axes ? (can't use transform.rotate) 1 Answer
Can't get object to move and rotate on its own axis 2 Answers