Dash Ablility

Updated 4 days ago in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
13 on May 14, 2018

What is the easiest and best way to make a dash ability that moves quickly in the direction the camera is currently facing.

  • Liked by
Reply
0 on May 14, 2018

The easiest and best way depends on how the rest of the movement in your game is handled.

 

However, this is one way you could go about doing it.

public IEnumerator DashForward(float speed, float distance)
{
    Vector3 cameraForward = Camera.main.transform.forward;
    for(float i = 0f; i < distance; i += (speed * Time.deltaTime))
    {
        transform.Translate(cameraForward * (speed * Time.deltaTime));
        yield return null;
    }
}

 

  • Liked by
Reply
Cancel
1 7 days ago

Thanks for the help but I have 2 problems. Firstly, for some reason the dash if trying to go in the + X axis it goes backwards and also how would I make it so it cannot go through floors and wals

 

6 days ago

Give everything Colliders, and give the Player a kinematic RigidBody as well.

 

Show more replies
  • Liked by
Reply
Cancel
1 6 days ago

I kind of want this dash ability to dash untill it either hits a collider or reaches the certain distance. I’ve expirimented with lots of things but it doesn’t work always going in the wrong direction.

 

6 days ago

That’s because I forgot to set the translate to world space.

 

Here is it fixed.

public IEnumerator DashForward(float speed, float distance)
{
     Vector3 cameraForward = Camera.main.transform.forward;
     for(float i = 0f; i < distance; i += (speed * Time.deltaTime))
     {
         transform.Translate(cameraForward * (speed * Time.deltaTime), Space.World);
         yield return null;
     }
}

 

Also, it does only go a certain distance, and if you set the colliders like I mention above, it should stop moving on collision, but it may still try to for a bit after until it should have reached the predefined distance.

Show more replies
  • Liked by
Reply
Cancel
1 6 days ago

It works but it still can go through walls.

6 days ago

Sorry, I had my physics backwards. Only the player needs a RigidBody (floors and walls don’t need one, but still can) and the player is NON-kinematic.

Sorry again.

Show more replies
  • Liked by
Reply
Cancel
0 6 days ago

Thanks for the help.

 

  • Liked by
Reply
Cancel
1 5 days ago

It still can go through walls and floors but I’m trying to fix it

 

Helpful
5 days ago

Did you give the walls a collider? And unchecked the checkbox for trigger only? Because a (3D) rigid body should collide with a collider if it is placed on your obstacles.

Show more replies
  • Liked by
Reply
Cancel
0 5 days ago

Yeah, they all have coliders but when I dash sometimes it stops at the wall but most times it goes through it.

 

  • Liked by
Reply
Cancel
1 4 days ago

Can it be that your ‘speed’ and ‘distance’ parameters are to big? Then it will skip the wall collider because it gets ‘teleported’ to the other side of the wall. Maybe you can use a raycast check and check if it hits a wall collider and then stop the ‘dash’ ability so it will stop at the wall. If you can; please tell your parameters you have used and place a screenshot one of the walls. I think this is what happends

4 days ago

transform.Translate uses the Physics engine and should handle collisions if the players Rigidbody is set up properly.

There is no need for extra checks.

Show more replies
  • Liked by
Reply
Cancel