i need help making a dash ability for my endless runner game
the best i could make is a script that teleports the player but im looking for more of a megaman like dash.
using UnityEngine; using System.Collections;
public class Dashing : MonoBehaviour {
 Vector3 tempPos;
 public float timeBetweenDashes = .1f;
 private float timestamp;
 void Update() {
     if(Time.time >= timestamp && (Input.GetKeyDown (KeyCode.D)))
     {    
         tempPos = transform.position;
         tempPos.x += 3f;
         transform.position = tempPos;
         timestamp = Time.time + timeBetweenDashes;
     }
 }
 
               }
here's my movement script.
using UnityEngine; using System.Collections;
public class Dashing : $$anonymous$$onoBehaviour {
 public float moveSpeed;
 private Rigidbody2D myRigidbody;
 
 void Start () {
     myRigidbody = GetComponent<Rigidbody2D> ();
 }
 void Update() {
     myRigidbody.velocity = new Vector2 (moveSpeed, myRigidbody.velocity.y);
 }
 
                  }
Answer by seilerf · May 16, 2016 at 01:48 PM
Could you post your movement class? I guess you have a default speed, why not just increase the movement speed for some seconds? Start a Coroutine which increases the speed, yield return WaitForSeconds(xy) and then decrease the speed.
Answer by treydarling · May 17, 2016 at 01:22 AM
still a little ugly but much better than what i had before
using UnityEngine; using System.Collections;
public class Dashing : MonoBehaviour {
 bool dashing = true;
 Vector3 tempPos;
 void Start()
 {
     
 }
 void Update () 
 {
     if (Input.GetKeyDown (KeyCode.D)) 
     {
         StartCoroutine ("TimerDash");
     }
 }
 IEnumerator TimerDash()
 {
     while (dashing) 
     {
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         Debug.Log ("Dash");
         tempPos = transform.position;
         tempPos.x += .5f;
         transform.position = tempPos;
         yield return new WaitForSeconds (.001f);
         StopCoroutine ("TimerDash");
     }
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
Making an object move non stop after button input? 1 Answer
How to tilt a sprite based on pointer position? 1 Answer
Movement Sticking 0 Answers
Hi, got a problem with my vertical axis. 0 Answers
How to specify forward direction for my character? 0 Answers