I am trying to make a ski game but my character does not move forward it only rotates left and right I have the input setup correctly but it does not seem to work.
I also want to add momentum to the character because I am making a ski game where you get speed as you go down the hill. How could I add this to the script?
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController=GetComponent(CharacterController);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
}
@Petaflops, he defined keys/buttons inside Input.GetAxis (), please learn basic programming before helping
@Waffle: you never told script to move. Also you don’t need to use TransformDirection as it’s only converting from Local to Global space.
to move simply use tranform.translate along Vector3.forward multiplied by speed, where speed is multiplied by Time.deltaTime to be multi-platform precise (it will move evenly whatever the framerate is)
ofcourse as usual i’ll let you do the code yourself, questions are welcome
@zaino: you are correct, if characterController is not used, simple box/sphere/capsule instead is used. But that can be fixed by detecting collision, to simulate stuff. CharacterController uses Skin width to detect collisions.
also:
the other way is to use physics movement with velocity set to rigidbody. But that takes more CPU.