Help with rotation please
Hi guys, I have a character that can walk however, he cannot look sideways then walk. So I decided to rotate him and depending on a button. My plan is that when a user press 'A' he would rotate to the left and then when they press w he start walking to the left. Now when they release these two buttons he would go back to his normal position. Below is my code and it works; however, if I keep pressing 'A' he would just keep adjusting his rotation and his rotation wouldn't be fixed to 183. So please can you view my code and just tell me what is wrong with it. Thank you!
void Update()
{
if (Input.GetKey(KeyCode.W)) // This is to check if the key 'W' is pressed and it works
{
anime.Play("walk", -1); //this is to play the animation and it works
}
if (Input.GetKeyDown(KeyCode.W & KeyCode.A)) //here is the problem
{
anime.Play("walk", -1);//here is the problem
transform.Rotate(0, 183, 0);//here is the problem
}
}
}
Answer by tanoshimi · May 08, 2016 at 07:12 AM
Not sure what the significance of the value "183" is, but I think instead of:
transform.Rotate(0, 183, 0);
You want:
transform.eulerAngles = new Vector3(0, 183, 0);
Answer by meat5000 · May 08, 2016 at 11:34 AM
Something more like this...
if( Input.GetKeyDown(KeyCode.W) && Input.GetKeyDown(KeyCode.A) )
But detecting a simultaneous press like that might be buggy.
After you've fixed that line the other problems should go away.
Your answer
Follow this Question
Related Questions
If-statements doesnt seem to be working.. (CODE IS CORRECT),Why isnt Unity seeing the if-statements? 1 Answer
If statement for direction the character is facing 0 Answers
The If statement condition is false but the if statement stills executes 1 Answer
Unity Update is ignoring the GetKey part of my statement!? 2 Answers
weird problem in C# 1 Answer