- Home /
Question by
JuanseCoello · Jul 17, 2013 at 08:03 PM ·
rotationcharacter movementstopkey press
Stop rotation if a key is pressed
I am trying to make the character stop its rotation if key E is pressed. If the character presses E + D it moves right If the character only presses D it rotates. But if the character presses E + D at the same time, the rotation around its axis stops.
if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical")); // Moves the character forward and back
if (Input.GetKey("e") & Input.GetKey("d"))
TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0); // The character moves sideways to the right in this case
if (Input.GetKey("d"))
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0); // The character rotates around its axis.
else if (Input.GetKey("e")) // This is the part when character stops rotating if E is pressed, not working.
rotateSpeed = 0;
Comment
Answer by markedagain · Jul 17, 2013 at 08:13 PM
in your else if statement you only populating your own rotateSpeed value, but never assign it to the transform.rotate.
Answer by JuanseCoello · Jul 17, 2013 at 08:17 PM
How could i assign the transform.rotate instead?
Like this:
else if (Input.GetKey("e")) transform.Rotate(0,0,0);
This doesnt work. It doesnt recognize this argument. How would be the correct way?
Your answer
![](https://koobas.hobune.stream/wayback/20220613110324im_/https://answers.unity.com/themes/thub/images/avi.jpg)