- Home /
Air-Dash phases through walls due to high velocity?
In short, I've been having issues with trying to prevent my rigidbody from being able to phase through walls if the character is close enough to the wall. Research has suggested that this is due to the (extremely) high velocity of the rigidbody, however I have attempted to use the "DontGoThroughThings" script and line/ray casts to prevent this to no avail. I have also attempted to use an "OnCollisionEnter" script on the walls themselves but also to no notable effect.
Here's the code for the air-dash coroutine:
IEnumerator airDash()
{
Vector2 distance = new Vector2();
//Remove all previous velocity before moving forward
rb2d.velocity = new Vector2(0, 0);
//If right arrow tapped twice, go right
if (tapDirection == 1)
{
distance = (dashLength.position - transform.position);
}
//Else if left arrow tapped twice, go left
else if (tapDirection == 2)
{
distance = (-dashLength.position + transform.position);
}
//Boosts player for set distance. Note: distance seems to increase/decrease based upon multiplication factor, not on distance itself.
rb2d.velocity = distance.normalized * 300;
//Brings to hard stop after dash. Seeking for it to also detect collisions properly.
if (rb2d.position == distance)
rb2d.velocity = new Vector2(0, 0);
yield return null;
}
Would perhaps using .addForce as opposed to directly velocity work more effectively? I've also considered using Transform to more directly affect the position of the rigidbody but have heard of inconsistent results regarding wall phasing from that method as well.
In short, I'd like a consistent-dash that only goes a set distance that doesn't phase through walls. Just like every other guy XD
Thank you very much for your feedback, I truly appreciate any advice or criticism you can offer :D
Your answer
![](https://koobas.hobune.stream/wayback/20220612054625im_/https://answers.unity.com/themes/thub/images/avi.jpg)