- Home /
Question by
Alter · Feb 16, 2014 at 12:58 PM ·
c#playerrotateeulerangles
Player Rotation
Hi guys, I'm currently having an issue with switching my character rotation to match the set direction.
Right now I'm currently using:
float moveDir = Input.GetAxisRaw("Horizontal");
if (moveDir !=0)
{
//transform.eulerAngles = (moveDir>0)?Vector3.up * 180:Vector3.zero;
}
Which is working prefectly, however I need to attach a 'left' and 'right' function to two seperate 'buttons'.
I have this, but the player keeps on facing the lefthand side but will move to the right.
if(Input.GetKeyDown("e"))
{
Debug.Log ("Left");
Player.transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
transform.eulerAngles = (moveDir>0)?Vector3.up * 180:Vector3.zero;
}
if(Input.GetKeyDown("r"))
{
Debug.Log ("Right");
Player.transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
transform.eulerAngles = (moveDir>0)?Vector3.up * 180:Vector3.zero;
}
Any help is greatly appreciated, thank you in advance.
PS: I'm using the 'e' & 'r' keys just to simulate a 'touch button' for the iOS/Android devices.
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Camera rotation around player while following. 6 Answers
Rotating a model with increments 1 Answer
Multiple Cars not working 1 Answer
Camera rotation behaving strangely 2 Answers