- Home /
Question about positive and negative imput values.
Hello !
So i was reading the documentation a while, and finnaly got this to work verry nicely ! But now im seriously bugged about something.
This part of the code makes the "ship" rotate to the left smoothly. This works perfectly.
//if you press A key ship will rotate Z + axis
if (Input.GetKey (KeyCode.A))
{
playerShip = Quaternion.Euler (0, 0, tiltAroundZ);
//Dampens twoards the rotation
transform.rotation = Quaternion.Slerp(transform.rotation, playerShip, Time.deltaTime * smooth);
print ("Horizontal Positive key A was Pressed");
}
What im wondering is why the code makes it rotate to the right if i change the keycode to D key. With the same values and exactly the same code as above ?
You need to clarify the actual question here. $$anonymous$$ost folks are more than happy to help but nobody want's to try and decode a question from a couple of different assumptions.
Alright ! updated. sorry it was a mess, i hope the question is understandable atm.
Answer by DavidDebnar · Feb 06, 2012 at 06:37 PM
You have it there! First you have //if you press A key ship will rotate Z + axis and than //if you press A key ship will rotate Z - axis. So in this case, raw A value returns 1 and raw D input value -1 so it rotates to the opposite direction! And the tilt value for horizontal rotation is negative so you will get positive tilt value for D and negative for A if I am sure. Go to project settings-input in unity and check the positive and negative value. AND you were wondering why does the ship tilt to right when you change the key code to D, well that's because you use the keycody only in the if statement and use axis in the tilt variable.
I am writing the code atm.
would you $$anonymous$$d clicking the tick under the thumbs up button?
Answer by Psychel · Feb 06, 2012 at 08:33 PM
Owh ! then i understand, i was a bit baffled that it returned - value and + value by its self. i thought i had to write a new if statement for each + and minus value. thanks for clearing that up !
Yeah the tilting i knew already why since that was the code i was writing, it was basicaly why did it tilt without me writing a positive value for the D.
You can copypaste the code and drag it onto a prefab with a player tag and it will auto work.
Thanks for clearing the part about negative and positive values given by the keycode. You were right about the positive and negative values given by the keys. it was autosetup. i never knew that so thanks again, i learned something new trough this.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063813im_/https://answers.unity.com/themes/thub/images/avi.jpg)