I'm trying to get my character to perform a "dash" where their x velocity increases rapidly and then falls over time. However, I'm also maintaining a constant x velocity so the character appears to be running at all times. The problem is trying to figure out when the dash should be considered finished. It can't be finished when the x velocity is equal to the running speed again, because other forces may be acting on the character.

It feels like all the information I need to figure this out is gone because it's all been calculated into the velocity vector, and the actual forces and where they come from are thrown out.

I've considered the following:

final = run + dash + other forces

But this means I couldn't use Unity's forces because I don't know what they're meant to act on(for example should a force pushing me down while I jump be applied to the jump velocity or the not?).

How can I determine how much force my dash should do and how much it should "undo" with the information given by Unity?


1 Answer 1


How much force should apply, it depends totally on your environment. What are the factors, I don't know.

But your undo thing can be achieve by Mathf.Clamp.

Suppose you have constant horizontal velocity of 5, then you can do something like,

Rigidbody _rb = GetComponent<Rigidbody> ();
_rb.velocity = new Vector3 (Mathf.Clamp (_rb.velocity.x, 5, 10000), 0, 0);

Here you can specify the minimum force, which is your constant force, and max, it is up to you, my recommendation is to keep this value high as 10000. By this you can apply AddForce and you character will be able to get back to your constant velocity.

  • \$\begingroup\$ But what if there's another force involved? For example, wind that blows the character backwards. Instead of the "non-dashing" velocity being 5 it is now, -3 for example, because the wind applies -8 horizontal velocity. How am I suppose to take this into account? \$\endgroup\$
    – Ben
    Commented Feb 25, 2016 at 13:41
  • \$\begingroup\$ it has two perspective, you want to say that you are handling your constant velocity variable? For example you are changing that if wind blows your character? \$\endgroup\$ Commented Feb 25, 2016 at 13:44
  • 1
    \$\begingroup\$ You should be using AddForce multiple times with different modes as needed \$\endgroup\$ Commented Apr 26, 2016 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .