I am using a joystick to make the character move using the CHaracter Controller script like this:
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var moveJoystick : Joystick;
var speed: float = 1.0;
var turnSpeed:float = 1.0;
var angle: float = 1.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
moveDirection.y -= gravity * Time.deltaTime;
if (moveJoystick.position.y>0) {
controller.Move(Vector3.forward * moveJoystick.position.y * speed);
}
else {
controller.Move(-Vector3.forward * moveJoystick.position.y * speed);
}
controller.Move(moveDirection * Time.deltaTime);
angle = Mathf.Atan2(moveJoystick.position.x, transform.rotation = Quaternion.Euler(new Vector3(0, angle,0));
}
The only problem is that the player does not move towards the direction it is facing. It just keeps going forward all the time.