Jump movement

hi guys :slight_smile:

I want that my zombies, when follow the player, make little jumps.

This is the script:

// Enemy AI
private var ismoving=false;    // is moving the Enemy?
private var target : GameObject;   // Enemy´s Target
var enemyVelocity = 5;            // Enemy´s Velocity
private var damage :int=5;                         // Enemy's Damage
private var attakingVelocity = 1;            // attack time rate
private var collisionDistance = 1.5;
var audioIdle : AudioSource;


function  Start(){
// set the target and starts to moving at start
target = GameObject.FindWithTag("Player");
ismoving = true;
}
function Update () {

//: if not moving, wait one second, else, if the enemy have a target, chase that target (player)
if(!ismoving)
{
   attakingVelocity += Time.deltaTime;
   if(attakingVelocity > 1)
   {
      ismoving=true;
      attakingVelocity = 0;

   }
}
else
{
if(target)
   ChasePlayer(target);

}

}


function ChasePlayer(target:GameObject)
{  
// look at target
      var direction =  target.transform.position - transform.position;
      direction.y=-10.0;
      var rotation = direction;

//rotate smoothly to the target´s direction
      transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), 3 * Time.deltaTime);
      transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);

// stablish the orientation
      var forward = transform.TransformDirection(Vector3.forward);

//Stablish the velocity variance depend on the target´s direction
      var speedModifier = Vector3.Dot(forward, direction.normalized);
      speedModifier = Mathf.Clamp01(speedModifier);

//if target reaches a certain distance between him and the player, hurts the player and stop moving, else, it continues moving
      if (Vector3.Distance(transform.position, target.transform.position) < collisionDistance) // Collision Distance is a var
       {
         ismoving=false;
		}
      
      else
      {
         direction = forward * enemyVelocity * speedModifier;
         if(GetComponent (CharacterController))
            GetComponent (CharacterController).SimpleMove(direction);
         else
         {
            rigidbody.velocity=direction;
            rigidbody.velocity.y=-1;
         }
      }
  
   yield;
}

thanks :stuck_out_tongue:

If the rigidbody also has gravity turned on, can’t you just set the up velocity of the rigidbody?

No, my enemies have the gravity on rigid body, infact i want that they jump with the scrip, I can’t set up velocity on rigid body only :wink: