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;
}
}
}
If you’re trying to do it that way, then don’t forget you can mess with velocity for each axis individually. If you only want the rigidbody to slow down on the x axis, whilst retaining gravity on the y axis, then try something like;
I ended up fixing it myself by checking for collision, and if there was none, the script just does not apply resistence. I tried your way afterwards, but it made the tank pretty much go straight down when the player drove it over an edge. Thank you for the info though, I used your way to apply gravity to the tank so it falls more realistically. Thanks!
Ah gotcha - I thought you had a different target behaviour in mind. More the kind of behaviour you’d expect from a jetpack than a tank though in retrospect.