- Home /
How to make a rigidbody2D character dash, without addforce
Hi,
I'm stuck on a bit of coding. Can anyone share their coding tips on how to make a rigidbody2d based character, Dash, without using "addforce" ?
Currently I'm using this , which kind of works. But the addforce is based on the characters speed. So standing still and using this code produces a tiny dash.
_rigidBody2d.AddForce(direction * _addDashForceValues, ForceMode2D.Impulse);
Thanks Sharin' is carin'
Answer by NerdRageStudios · Sep 18, 2017 at 01:52 AM
Why not just addforce only when velocity is over a certain threshold, thus preventing player from using it when still... you can check this with rb.velocity.magnitude
@ NerdRageStudios I can try that. But Again the dash distance isn't consistent since it seems to be based on the characters initial speed... or from what I can gather (I'm a newb coder btw)
I was hoping to find a solution based on transform.translate. I managed to find some people discussing this kind of code. But it's still a bit wonky to use, my character crashes into colliders etc.
Vector3 _direction = (_target.transform.position - transform.position).normalized;
_rigidBody2d.$$anonymous$$ovePosition (transform.position + _direction * 15f * Time.deltaTime);
Answer by IndievdB · Sep 18, 2017 at 02:13 AM
If you want to be more precise with a your character's velocity, you can always set it directly with something like:
_rigidBody2d.velocity = direction * _addDashForceValues;
but this may require a bit more overhead.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
How do I make a dash attack while doing a top down 2d game 1 Answer
Smooth dashing issues 0 Answers