Setting a delay before dashing.

Hey guys,

Me again. Lol. So the problem I’m facing right now is with our character’s dash. I right now it’s just bumping up the running speed of our character inside of fixed update and it’s working like a dash. The thing is though, is that the transition is so smooth between the two it’s almost un-noticable.

What I want to do is have my character stop completely and THEN dash to the direction specified, so that the dash is more apparent. I’ll attach my script for all to see. I really don’t know how I can do this exactly… any and all help will be appreciated! Thank you!

Condor

ThirdPersonController.Cs

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ThirdPersonController : MonoBehaviour
{
	GameObject player;
	Targetting targetting;
	TP_Animator anim;
	katCollision katanaCol;
	
	public Vector3 movement1 = Vector3.zero;
	
	public Transform myTransform;
	
	public new cameraCode camera;
	
	public bool isAttacking;
	
	//Lock on deselect
	public bool deselectTimer =  false;
	
	public float speed = 1.0f;
	
	//Run Speed, Walk speed, Strafe Speed etc...
	public float runSpeed = 1.7f;
	public float strafeSpeed = 1.5f;
	public float walkSpeedDownscale = 2.0f;

	//dodge variables Timer = lifetime, Speed = distance
	public bool isDodging = false;
	public float dodgeTime = 0.25f;
	public float dodgeSpeed = 5.0f;
	
	public LayerMask groundLayers = -1;
		//Make sure that the player is not on the same layer as the environment
	
	private const float inputThreshold = 0.01f;
	public const float groundDrag = 6.0f;
	public const float dragwhileDodge = 2f;
	public float dodgeDrag = 0f;
	public float dodgeRecover = 0f;
	public float isattackingTime;
		
	private bool walking;
	
	public TP_Animator animator;
	
	public AudioSource RunRight;
	public AudioSource RunLeft;

	void Start ()
	// Verify setup, configure rigidbody
	{	
		player = this.gameObject;
		
		anim = GetComponent<TP_Animator>();
		
		// find targetting script
		targetting = transform.GetComponent<Targetting>();
		
		myTransform = transform;

		rigidbody.freezeRotation = true;
			// We will be controlling the rotation of the target, so we tell the physics system to leave it be
		walking = false;
		
	}
	
	public void Update ()
	{	
		dodgeRecover -= Time.deltaTime;
		isattackingTime -= Time.deltaTime;
		
		if(isattackingTime >= 0.6f)
		{
			isAttacking = true;
		}
		else if(isattackingTime <= 0)
		{
			isAttacking = false;
		}
		
		rigidbody.drag = groundDrag;
		// Apply drag when we're grounded
		
		if(Input.GetButtonDown("Fire1") && isDodging == false && dodgeRecover <= 0f) // dodge
		{
			dodgeRecover = 1.0f;
			
			StopCoroutine("Dodge");
			StartCoroutine("Dodge");
	
			dodgeDrag = groundDrag - dragwhileDodge; 
		}
		
		if(isAttacking == false && isDodging == false)	
		{
			movement1 = new Vector3(Input.GetAxis ("Horizontal") , 0f, Input.GetAxis ("Vertical"));
			movement1.y = 0f;
		}
		
	}
	
	void FixedUpdate ()
	// Handle movement here since physics will only be calculated in fixed frames anyway
	{
	
		if(isAttacking == false)
		{
			float appliedSpeed = walking ? speed / walkSpeedDownscale : speed;
			
			if(Input.GetButtonDown("LockOn"))
			{
				appliedSpeed = walking ? strafeSpeed / walkSpeedDownscale : strafeSpeed;
			}
			else
			{
				appliedSpeed = walking ? runSpeed / walkSpeedDownscale : runSpeed;
			}
		
			Vector3 relativeMovement = movement1;

			if(targetting.selectedTarget != null)
				relativeMovement = rigidbody.transform.TransformDirection(relativeMovement);
			else
				relativeMovement = Camera.main.transform.TransformDirection(relativeMovement);
			
			relativeMovement.y = 0f;
			
			rigidbody.AddForce (relativeMovement * appliedSpeed, ForceMode.VelocityChange);
		
			if (targetting.selectedTarget == null && relativeMovement != Vector3.zero && !isDodging)
				transform.forward = relativeMovement.normalized;
		}
	}	
	
	void RunRightNow()
	{
		RunRight.Play();
	}
	
	void RunLeftNow()
	{
		RunLeft.Play();
	}
	
	IEnumerator Dodge()
	{
		isDodging = true;
		yield return new WaitForSeconds(dodgeTime);
		isDodging = false;
	}

}

scroll down to

Make something happen in the future

and

delaying an action