How do I make movement slow with drag on a rigidbody2d?

I am remaking a game I made in 3D as a 2D game because it looks better that way, but I am having trouble getting the players to slow to a stop like they did in the 3D version. Here you can see the player just keeps moving after the initial force is added - Imgur: The magic of the Internet

I’m adding force with the following cod:

p1.obj.GetComponentInChildren<Rigidbody2D>().AddForce(p1.obj.GetComponentInChildren<Rigidbody2D>().transform.right * p1.charge, ForceMode2D.Impulse);

I have tried adding ludicrous amount of drag but all it does is dampen the initial force, once the player starts moving they don’t stop.

If your having trouble with this the easiest fix seems to be to just trash your 2d project and make it again as a 3d project with an orthogonal camera and fake the 2d. That was my fix.

Linear drag is applied per simulation step and will continue to reduce the velocity. You are also obviously free to modify velocity yourself with a simple function to give you any type of drag.

The linear and angular drag code can be found here if you’re interested: box2d/Box2D/Dynamics/b2Island.cpp at ef96a4f17f1c5527d20993b586b400c2617d6ae1 · erincatto/box2d · GitHub

Redoing all your code in 3D seems a bit drastic but if you’re happy. This is such a basic function so no idea what’s going wrong.

The code you posted above isn’t so great. Finding components multiple times to add a force isn’t going to be fast either.

Yeah I should really optimize that line by assigning a variable to the rigidbody. In my case I already had a fully working version of the game in 3d and was changing it to 2d so trashing the 2d project was as easy as switching a branch in git. The fact that the drag is so basic is what made this so hard I ended up giving up. I couldn’t find others with the same problem and no one wanted to help since it seems like this just works for everyone else. The most common advice I found was to increase the drag or the angular drag but that only affected the initial force required to get the object moving, once it started no matter how high the drag was it never stopped.

The only way that can happen on a body is if a force is being continually applied to counteract the drag (you already stated it’s once only) or if the body-type isn’t Dynamic but is in-fact Kinematic which doesn’t have any forces such as gravity, drag applied to it (as can be seen in the conditional body-type state in the Box2D link above).

Its weird right? you can see in the gif I attached originally that it is Dynamic. There is another force being applied to the ridgidbody every frame to make it rotate (you can see that with the spinning arrow) but I even tested with that code commented out so that the object was no longer rotating and had the same effect. It was too weird of an issue and I couldn’t find a solution. (Sorry future googler that finds this, I hope you find some help somewhere.)

Well if you look at the inspector, the Transform position isn’t changing so the body isn’t moving yet it obviously is in the image so you’re doing something else here. Is the above a child and you’re also moving the parent (should not do this)? That would mean what we’re seeing in the image is the local position.

I mean, grab a body, place it on a GameObject and just test it and it’ll slow down. In your case above, something else is moving the hierarchy.

Whilst the image in your mind clearly shows what’s happening, it’s not so clear when you’ve not see the project, hierarchy and code tbh. :frowning: