Hi, i have been working on a top down movement script but i got stuck when it came to rotation, what i want is that the character is always looking at the way the character is going. (So if the player is pressing left/a the character should be going that way and be facing to the left)
This is what i have so far, some advice to what i am supposed to do and how i’m supposed to do it would be very cool.
private var xKey : float;
private var zKey : float;
private var diagonalSpeed : float = 1;
var speed : float = 10.0;
var Stunned : boolean = false;
var Sprinting : boolean = false;
function Update () {
if(!Stunned){
// Checks if player presses button and calculates movement speed.
zKey = (Input.GetAxis("Vertical") * speed);
xKey = (Input.GetAxis("Horizontal") * speed );
}
// If player is pressing an arrowkey add speed to the character, if two buttons are pressed reduce the speed.
if((xKey != 0) (zKey != 0)) {diagonalSpeed = 0.75;} else {diagonalSpeed = 1;}
rigidbody.velocity = Vector3(xKey * diagonalSpeed,0,zKey * diagonalSpeed);
if(Input.GetKey("left shift") (!Stunned))
{
speed = 15;
Sprinting = true;
}
else
{
speed = 10;
Sprinting = false;
}
}
// Thanks