Hi i have been working on making my character turn the way the character is going for my top down game. I know i'm missing something very obviuos that will make it alot easier and make the script work to begin with but i'm still quite new to scripting and i cant figure it out. What i'm trying to do in my script at the moment is just rotating the graphics to not mess up the controller. This is what i got right now, and it's not working as you can most likely see.
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;
var playerParts : GameObject;
var lastDirection : int = 1;
function Update () {
if(!Stunned){
zKey = (Input.GetAxis("Vertical") * speed);
xKey = (Input.GetAxis("Horizontal") * 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;
}
if(Input.GetKey("a") && (lastDirection != 3))
{
lastDirection = 3;
playerParts.transform.Rotate(0, -90, 0);
}
if(Input.GetKey("d") && (lastDirection != 4))
{
lastDirection = 4;
playerParts.transform.Rotate(0, 180, 0);
}
}
Any suggestions how i can do this would be cool.
Still having trouble with this? Just wondering because it's been a while since you've posted.
– dre38w