

These are documented with the 3D ForceMode, but the principle is the same in 2D. The best way to think about the force modes in my opinion is to think about their units. Trying to approximate a dash using forces, and finding the length, is like shooting a gun in space and asking how long before the bullet slows down.Īlthough, I understand that this is not actually an answer to your question, so if you still want to do what you are doing, it's important to quickly look at: The physics engine is great for newtonian physics, but most often a character is not subject to these same laws- a dash might be the result of the character kicking off with their feet inhumanly fast, or something much more bizzare, like magic or some sort of sci-fi gadget, and regardless, nothing in real life really dashes the way a game character should. It also makes it much more intuitive for you to edit.

This means that balancing is easier, and it opens the door for easily adding modifiers, different character stats, status effects, etc. This allows the direction to still change freely in-dash.įurthermore, I highly recommend this method over forces because you maintain more explicit control over how the character dashes. Save the initial magnitude of their velocity, for instance, and when the dash is over, set the magnitude of their current velocity back to the previous magnitude or their current, whichever is smaller. Right now I just approximated the time by dividing the force I add (usually around 50) by 100 and it looks quite accurate for small forces, but I don't really like this solution.įirst, the easy (and recommended) way outĬonsider making your character have a set dash time (or dash distance) to begin with. Any collisions or actions that happen along the way are irrelevant for me, I only need the time. I do this with AddForce and it works great! But I need to know for how long the character is dashing so things can happen in that period of time. The in-game situation is: I have a character that performs 'dash'. I need to calculate this using only starting parameters as the actual velocity can change by other means as well. Now the question is, is it possible to calculate time in which this force will be affecting my velocity if I know starting velocity, mass and everything else I can get from RigidBody2D? I have an object that I add force to using Rigidbody2D.AddForce with ForceMode2D.Impulse as a parameter. Ok, I couldn't formulate this question simple enough to google it effectively, so I hope I can get some help here.
