I’d just got the unity basic edition last night, and I spent a bunch of time in the tutorials and I’ve finally created my first script. My script involves an object that moves around with the WASD keys, and the A and D keys modify the torque to rotate the item. After a while of playing around with it, I realized the torque wasn’t going back down when I let go of the key that modifies it. How would I achieve that? This is the portion of my script that controls all of that:
bool accel = Input.GetKey(KeyCode.W);
bool left = Input.GetKey(KeyCode.A);
bool right = Input.GetKey(KeyCode.D);
if(accel)
{
rigidbody.AddForce(-transform.forward * 25);
}
if(left)
{
rigidbody.AddTorque(-transform.up * 2);
}
else if(right)
{
rigidbody.AddTorque(transform.up * 2);
}
else
{
rigidbody.AddTorque(transform.up * 0);
}
I would really appreciate some help, thank you!