Jumping enemy

mersox

Active member
I'm trying to have an enemy that doesn't walk around, he jumps all around making him a pain in the butt to get a hold on. I just don't know how to accomplish this.

If I use "nomove 1", he doesn't walk (good), but only jumps occasionally (bad). Mostly he'll just stand around like an idiot, waiting to be punched.

If I forget about "nomove" and only remove the "walk" animation, he just hovers around.

Using jumpframe in the walk animation is awkward as he would only jump once.

Any ideas?
 
If he don't need to walk, perhaps you can "overwrite" his walk anim with a fake jump and landing anim.

So when he will try to walk, he will do jumps instead.

Or code freespecial attacks of a jump anim that triggers easily in various distances from player(s)

Just some of my ideas...
 
nedflandeurse said:
If he don't need to walk, perhaps you can "overwrite" his walk anim with a fake jump and landing anim.

So when he will try to walk, he will do jumps instead.

Or code freespecial attacks of a jump anim that triggers easily in various distances from player(s)

Just some of my ideas...

Thanks man. I tried the "fake jumping" within the walk animaion but it looks buggy, specially when changing directions.

I'll just create a simple walk animation. Darn this project will never end, things like this keep popping up aarrrrgh
 
I've made such enemy before which jumps instead of walk. This enemy uses targetting script to ensure it jumps toward player (not jump right at player)
I set this in his WALK animation:

anim walk
@script
void self = getlocalvar("self"); //Get calling entity.

changeentityproperty(self, "velocity", 0, 0);
        setidle(self, openborconstant("ANI_IDLE"));
@end_script
...

The script is to forcefully cancel WALK animation before enemy walks
I do this cause setting nomove 1 1 also sets nodrop 1 which I don't want for this enemy

As for its wa.. jump AI or I should say movement AI, so far I only has random jump function which makes enemy jumps to random direction.
It is rdodgez posted below:

Code:
void dodgez( float Vx, float Vy, float Vz )
{// Dodge by moving up or down depending on z location
    void self = getlocalvar("self");
    int z = getentityproperty(self, "z");
    int dir = getentityproperty(self,"direction");

    if(dir==0){ // Facing left?
      Vx = -Vx ;
    }

    if(z > (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z")) / 2 ) {
      Vz = -Vz ;
    }

    if( Vx!=NULL() && Vy!=NULL() && Vz!=NULL() ){
      changeentityproperty(self, "velocity", Vx, Vz, Vy); //Dodge away!
    }
}

void Rdodgez( float Vx, float Vy, float Vz, float Rx, float Rz )
{// Dodgez with random velocity effect
// Only randomize x and z velocities
// Vx : x velocity
// Vy : y velocity
// Vz : z velocity
// Rx : x velocity randomness effect
// Rz : z velocity randomness effect
   int iDX;
   int iDZ;

   if(Rx!=0){
     iDX = (rand()%(Rx*10)*0.1);
   } else {
     iDX = 0;
   }

   if(Rz!=0){
     iDZ = (rand()%(Rz*10)*0.1);
   } else {
     iDZ = 0;
   }

   dodgez( Vx+iDX, Vy, Vz+iDZ );
}

I include dodgez as well since Rdodgez calls it
This function is set in enemy's attack animaiton like this:

anim attack1
range 0 900
rangez -200 200
delay 1
offset 128 96
bbox 113 27 37 69
frame data/chars/troglodyte/idle1.png
delay 10
bbox 110 58 45 48
frame data/chars/troglodyte/jump1.png
delay 14
bbox 113 34 34 42
@cmd Rdodgez 0 2 0 3 1
sound data/chars/gnolla/sounds/jump.wav
frame data/chars/troglodyte/jump2.png
frame data/chars/troglodyte/jump3.png
frame data/chars/troglodyte/jump2.png
delay 30
bbox 110 58 45 48
frame data/chars/troglodyte/jump1.png

This attack animation will be used as its movement.
Work great in my end :)
 
Bloodbane said:
I've made such enemy before which jumps instead of walk. This enemy uses targetting script to ensure it jumps toward player (not jump right at player)
I set this in his WALK animation:

anim walk
@script
void self = getlocalvar("self"); //Get calling entity.

changeentityproperty(self, "velocity", 0, 0);
        setidle(self, openborconstant("ANI_IDLE"));
@end_script
...

The script is to forcefully cancel WALK animation before enemy walks
I do this cause setting nomove 1 1 also sets nodrop 1 which I don't want for this enemy

As for its wa.. jump AI or I should say movement AI, so far I only has random jump function which makes enemy jumps to random direction.
It is rdodgez posted below:

Code:
void dodgez( float Vx, float Vy, float Vz )
{// Dodge by moving up or down depending on z location
    void self = getlocalvar("self");
    int z = getentityproperty(self, "z");
    int dir = getentityproperty(self,"direction");

    if(dir==0){ // Facing left?
      Vx = -Vx ;
    }

    if(z > (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z")) / 2 ) {
      Vz = -Vz ;
    }

    if( Vx!=NULL() && Vy!=NULL() && Vz!=NULL() ){
      changeentityproperty(self, "velocity", Vx, Vz, Vy); //Dodge away!
    }
}

void Rdodgez( float Vx, float Vy, float Vz, float Rx, float Rz )
{// Dodgez with random velocity effect
// Only randomize x and z velocities
// Vx : x velocity
// Vy : y velocity
// Vz : z velocity
// Rx : x velocity randomness effect
// Rz : z velocity randomness effect
   int iDX;
   int iDZ;

   if(Rx!=0){
     iDX = (rand()%(Rx*10)*0.1);
   } else {
     iDX = 0;
   }

   if(Rz!=0){
     iDZ = (rand()%(Rz*10)*0.1);
   } else {
     iDZ = 0;
   }

   dodgez( Vx+iDX, Vy, Vz+iDZ );
}

I include dodgez as well since Rdodgez calls it
This function is set in enemy's attack animaiton like this:

anim attack1
range 0 900
rangez -200 200
delay 1
offset 128 96
bbox 113 27 37 69
frame data/chars/troglodyte/idle1.png
delay 10
bbox 110 58 45 48
frame data/chars/troglodyte/jump1.png
delay 14
bbox 113 34 34 42
@cmd Rdodgez 0 2 0 3 1
sound data/chars/gnolla/sounds/jump.wav
frame data/chars/troglodyte/jump2.png
frame data/chars/troglodyte/jump3.png
frame data/chars/troglodyte/jump2.png
delay 30
bbox 110 58 45 48
frame data/chars/troglodyte/jump1.png

This attack animation will be used as its movement.
Work great in my end :)

Perfect, man! I'll try this tomorrow.
 
Oh yes I forgot to explain the setting I'm using the example.

Rdodgez 0 2 0 3 1

Means troglodyte will jump with velocity 2 (2nd parameter) upwards (similar to jumpframe 0 2). x and z velocity is randomized. x velocity is a random value between -3 and 3 while z is between -1 and 1.

You might need to play around with the values to get the desired effect :)
 
I finally tried it and works great, until the enemy steps partially out of frame, either on the left or on the right border. When that happens, he just stands there and doesn't move anymore.
 
Ah that's the drawback of using attack animation to replace walking.

There are 3 ways to solve this:
1. The obvious solution is to increase range so enemy will always 'attack', jump in this case
2. Set loop to make enemy always jump around + set script to change to real attack animation. This is a function that could be used:
Code:
void attack1(int RxMin, int RxMax, int Rz, void Ani)
{// Attack interruption with range check
    void self = getlocalvar("self");
    void target = findtarget(self); //Get nearest player
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    int dir = getentityproperty(self, "direction");

    if(target!=NULL()){
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "z");
      float Disx = Tx - x;
      float Disz = Tz - z;

      if(Disz < 0){
        Disz = -Disz;
      }

      if( Disx >= RxMin && Disx <= RxMax && Disz <= Rz && dir == 1) // Target within range on right facing?
      {
        performattack(self, openborconstant(Ani)); //Change the animation
      } else if( Disx >= -RxMax && Disx <= -RxMin && Disz <= Rz && dir == 0) // Target within range on left facing?
      {
        performattack(self, openborconstant(Ani)); //Change the animation
      }
    }
}

Set one like this:

anim  attack1
  range  0 900
  rangez  -200 200
  loop    1
  delay  1
  offset  128 96
  bbox  113 27 37 69
  frame  data/chars/troglodyte/idle1.png
  delay  10
  bbox  110 58 45 48
  @cmd  attack1 -100 100 10 "ANI_FOLLOW1"
  frame  data/chars/troglodyte/jump1.png
  delay  14
  bbox  113 34 34 42
  @cmd  Rdodgez 0 2 0 3 1
  sound  data/chars/gnolla/sounds/jump.wav
  frame  data/chars/troglodyte/jump2.png
  frame  data/chars/troglodyte/jump3.png
  frame  data/chars/troglodyte/jump2.png
  delay  30
  bbox  110 58 45 48
  frame  data/chars/troglodyte/jump1.png

In this example, troglodyte will jump around randomly and if it detects player after landing, it will change to FOLLOW1 where it performs an attack
3. Use another attack animation to make enemy jumps inscreen to prevent it from being left behind or from jumping offscreen
Let me look for the proper function for this
 
Back
Top Bottom