nst-99
1
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?
fafase
2
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.