- Home /
This question was
closed Feb 05, 2017 at 09:34 PM by
PresidentPorpoise for the following reason:
Other
Question by
PresidentPorpoise · Feb 06, 2017 at 08:22 AM ·
scripting problemphysicsscripting beginnerphysics2dscriptingbasics
How can I slow the velocity of my player without it affecting fall speed?
I have been trying to slow my player to a stop when a key is not pressed. I have accomplished this by multiplying the rigidbody(2D)'s velocity by a decimal. However, the problem is that the tank falls very slowly. Is there anyway I can get it to not affect this? Should I implement a gravity multiplyer? Or is there a simpler way? Thanks in advanced.
here is my code:
public float force;
public float resistence;
public Rigidbody2D tank;
private void Start()
{
tank = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
if (Input.GetKey("w"))
{
force = 10;
tank.AddForce(transform.right * force);
}
else if (Input.GetKey("s"))
{
force = 10;
tank.AddForce(-transform.right * force);
}
else if (!Input.GetKey("s") || !Input.GetKey("s"))
{
tank.velocity = tank.velocity * resistence;
}
}
}
Comment