AddTorque turning not rotating opposite direction.
if (Input.GetKey("a"))
{
Debug.Log("A");
rb.AddTorque(Input.GetAxis("Horizontal") * -turnSpeed);
}
else if (Input.GetKey("d"))
{
Debug.Log("D");
rb.AddTorque(Input.GetAxis("Horizontal") * turnSpeed);
Both pressing 'A' and 'D' turn the same direction when I would like 'D' to turn the opposite way. The rigidbody is 2D by the way.
Any help? Thanks!
Answer by Salimrichab · Mar 14, 2017 at 09:36 AM
Had same issue, but i figured it out just now. The problem is in the method Input.GetAxis("Horizontal") , it compute the direction, negative for left, positive for right, so when you turn left it gives you a negative value, and what you are doing now is multiplying it with negative turnspeed, so it give again a positive number !! Hope my answer is not too late.
Answer by IgorAherne · Mar 13, 2017 at 01:19 AM
I suspect you are not entering the d
part of the code.
comment out addTorque and try rb.rotation += turnSpeed;
and rb.rotation -= turnSpeed;
for a respectively