Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Calculating the force required to travel a specific distance

Discussion in 'Physics' started by Duskman0, Aug 2, 2020.

  1. Duskman0


    Apr 28, 2019
    I'm trying to implement a dash mechanic in my 2D sidescroller game with physics based movement that allows you to dash a set distance in the 8 cardinal directions. Lets say I essentially want the player to be able to dash 5 units in any of the 8 cardinal directions, and I'd like to write a script that calculates the force required to do that, then applies that force. How would I go about setting up this math?

    Note: if needed, the character's mass is 1, their drag is 0, and the gravity in the game is set to -20 in the y value.
  2. AlTheSlacker


    Jun 12, 2017
    Allows you to understand the distance (s), time (t), velocity (u and v), acceleration (a) relationship. Scroll down to the bit "Constant translational acceleration in a straight line" to avoid the rather intimidating start.

    Force = mass x acceleration lets you work out the force to apply (the time will be the fixed physics time step or multiples of).

    You will need to compensate for your gravity, you can use the F = ma above to work out the force due to gravity.