- Home /
How to do a "dash"-movement, set distance on key-input?
I'm trying to add a directional "dash" to my current 2,5D Sidescroller-projekt. It would basicly be a movement into the direction the character is facing when a specific key is pressed. The distance traveled would be a set amount.
My first thought would be a simple "transform.position", though that would be more of a teleport than a dash.
What I am trying to make is a movement with increased speed that can't be cancled once activated and has a little cool-down before it can be activated again. Therefor I thought a Coroutine might work.
I already have a key for it set in the projects input settings, though what I really don't know anything about is how I can make the character move instead of just teleporting, especially since collisions are still supposed to apply. I have a script for moving platforms:
public int Marker = 0;
public Transform[] Waypoints;
void Update ()
{
transform.position = Vector3.MoveTowards(transform.position, Waypoints[Marker].transform.position, 3 * Time.deltaTime);
if (transform.position == Waypoints[Marker].transform.position)
{
Marker ++;
}
if (Marker == Waypoints.Length)
{
Marker = 0;
}
}
And thought to use the same way of transforming. My idea was to also work with waypoints, but I'd have to move them when the character walks normally and stop them once the character dashes. Also I have no real idea how to change the speed.
So to summarize:
I'm trying to make a dash in the direction the character is facing, a movement with collision on key-input and with a set distance that is the same for each dash. The dash therefor has a duration and a cool-down. Though I have a few little ideas as stated above, I don't know if they could work or how to fully make use of them (still fairly new to Unity).
If the "dash in currently faced direction" is harder to do, I can settle for two dash-methods (left and right) if necessary.
So, how could I do this?