- Home /
How can i make my enemy jump with a delay
I am making a runner game with 5 lanes. The enemy is moving at the same time as the player in the same direction but i want to make a delay for the enemy so that the player is able to dodge the enemy. It is now impossible to dodge the enemy. I use transform.position to move to the player lane and i use transform.translate to move the enemy to the lane.The player and the enemy are moving at the same speed. If i make the movement of the player faster than will the enemy teleport to the player's position.
   void moveJEnemy()
     { 
         if (moveEnemy == true)
         {
             if (lastLaneNumber == laneNumber + 1 && transform.position.x >= xLocation)
             {
                 transform.Translate(Vector3.left * Time.deltaTime * 15);
             }
             else if (transform.position.x >= xLocation)
             {
                 resetReq = true;
             }
 
             if (lastLaneNumber == laneNumber - 1 && transform.position.x <= xLocation)
             {
                 transform.Translate(Vector3.right * Time.deltaTime * 15);
             }
             else if (transform.position.x <= xLocation)
             {
                 resetReq = true;
             }
 
             if (resetReq == true)
             {
                 resetReq = false;
                 Vector3 pos = transform.position;
                 pos.x = xLocation;
                 transform.position = pos;
                 lastLaneNumber = laneNumber;
                 moveEnemy = false;
             }
         }
     }
Answer by haim96 · Nov 05, 2014 at 12:28 PM
you can start coroutine with waitforsecond() :
 IEnumerator MyMethod() {
   Debug.Log("Before Waiting 2 seconds");
   yield return new WaitForSeconds(2);
   Debug.Log("After Waiting 2 Seconds");
   moveJEnemy();
  }
when you want to jump :
  startcorutine(MyMethod());
it will wait 2 second then jump...
i found the answer it is close. i had to replace else if (transform.position.x <= xLocation) to else if (transform.position.x >= xLocation)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                