Dash/Leap to defined screen position

mtrain

New member
How to force the enemy to perform leap or dash move to a defined coordinates and stop there.

I have modify script for targeting:

void xytarget(int Xc, int Yc, float Velx, float Velz, float dx, float dz, int Stop)
{// Targetting opponent before leaping or dashing.
// Velx = x Velocity
// Velz = z Velocity
// dx = x added distance
// dz = z added distance
// Stop = flag to stop moving if no target is found

    void self = getlocalvar("self");
    int dir = getentityproperty(self, "direction");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    if (dir == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
    }

    setlocalvar("T"+self, findtarget(self)); //Get nearest player

    if( getlocalvar("T"+self) != NULL()){
      void target = getlocalvar("T"+self);
      float Tx = (openborvariant("xpos") + Xc);
      float Tz = (openborvariant("ypos") + Yc);

      if(Tx < x){
        changeentityproperty(self, "direction", 0);
      } else {
        changeentityproperty(self, "direction", 1);
      }

      x = x+dx;
      z = z+dz;
      float Disx = Tx - x;
      float Disz = Tz - z;

//Set both distance as positive value
      if(Disx < 0){
        Disx = -Disx;
      }

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

// Calculate velocity for targetting
      if(Disz < Disx)
      {
        if(Tx < x){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }

        setlocalvar("z"+self, Velx*(Tz-z)/Disx);
      } else {
        if(Tz < z){
          setlocalvar("z"+self, -Velz);
        } else { setlocalvar("z"+self, Velz); }

        setlocalvar("x"+self, Velz*(Tx-x)/Disz);
      }

    } else {
      if(Stop == 1)
      {
        setlocalvar("z"+self, 0);
        setlocalvar("x"+self, 0);
      } else {
        setlocalvar("z"+self, 0);
        if(dir==0){
          setlocalvar("x"+self, -Velx);
        } else { setlocalvar("x"+self, Velx); }
      }
    }
}

So i put next command to the enemy attack move:

@cmd xytarget 480 400 5 5 0 0 1 with  @cmd leap or dash

where 480 is the center of the screen x coordinate and 400 is the coordinate in z axis.
But the problem is i can not make enemy to stop when he reach that coordinates, he just continue to move. How to make him stop? Thank you)
 
I have function to make leap to defined coordinate and it was only used in pair with leap function. It was years ago and after some experience, I know that it can be used with dash function as well

Anyways, do you notice the basic difference between target and targetL function?
No, it's not "one for dash and the other for leap"! the basic difference is that target calculates required speed to get to target with defined maximum x and z speed while targetL calculates required speed with defined time to get to target.

Because of the latter, I can tell how much time required for targetting entity to reach target and thus I can tell them when to stop
And because of that function for leap/dash to defined position is based on targetL.

Let me find the one from Crime Buster for you but in mean time you can see this script:

Code:
@script
  if(frame==4){
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float Tx = openborvariant("xpos") + openborvariant("hResolution")/2;
    float Tz = (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z"))/2;
    float Vx;
    float Vz;

    Vx = (Tx-x)/66;
    Vz = (Tz-z)/66;

    tossentity(self, 3, Vx, Vz);
  }
@end_script

this script is used to make enemy jumps to center of playing field at frame 5. It jumps with 3 velocity so you can estimate that it will land about 60 centiseconds later
 
Anyways, do you notice the basic difference between target and targetL function?

Oh, i see now.

Let me find the one from Crime Buster for you

Thank you, this one is really important for my Mod. Now i am trying to make a boss to jump at the top center of walkable area after death. And the problem is that if he dying near that spot, he jumps to it with a little fault, but if he dies outside the screen he cant reach that spot and lands far from it. So i need a script that will automatically calculate which velocity and timing need to reach defined spot from any place of the screen (or maybe a script that i can modify for that)
 
I think it is also important to set defined frames number of jumping move and their delay, and, saying, if i set number of frames to 5, delay to 20, distance to target is easy to calculate, so the only variable we need is Vy, Vx and Vz, that, i think easy to calculate. So the script of targeting defined spot (not entity) is not so hard to make?

I have experiment and my calculations are next:

In Y movement:
Px/(D*Vy)=Fr

In X movement:
Px/(D*Vx*2)=Fr

In Z movement:
Px/(D*Vz)=Fr

Where:
Px - is a distance between entity and target
D - is a delay of the frames
Fr - frames during the move (leap or dash)
Vx, Vy, Vz - velocities

I use this calculations for make moving decorations (elevators, tunnels..) and they work perfectly, so i think they can be applied to targeted leap/dash script.

So ok, i modify a targetl script to next:

void xyleap(int Xc, int Yc, int Fr, int D)
{// Targetting X and Y position coordnates and perform a dash/leap
//Xc - x coordinate from the left side of the screen
//Yc - y coordinate from the top side of the screen
//Fr - frames to move
//D - delay of frames

    void self = getlocalvar("self");
    float x = getentityproperty(self, "x"); // Get enemy's x coordinate
    float z = getentityproperty(self, "z"); // Get enemy's z coordinate

      float Tx = (openborvariant("xpos") + Xc); // Get position's x coordinate
      float Tz = (openborvariant("ypos") + Yc); // Get position's z coordinate

      if(Tx < x){
        changeentityproperty(self, "direction", 0); // Face left
      } else {
        changeentityproperty(self, "direction", 1); // Face right
      }
      setlocalvar("x"+self, 2*(Tx-x)/(Fr*D*2)); // Calculate Vx then store value in local variable
      setlocalvar("z"+self, 2*(Tz-z)/(Fr*D)); // Calculate Vz then store value in local variable
      setlocalvar("y"+self, 0); // Calculate Vy then store value in local variable
}

and use it:

anim attack1
loop 0
offset 330 340
delay  50
@cmd xyleap 480 400 8 10
        frame data/chars/enemy/128.gif
@cmd dash
delay  10
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif
        frame data/chars/enemy/128.gif

@cmd stop
        frame data/chars/enemy/128.gif

So this is exactly what i need for dash, and it is work perfectly.
During this attack move enemy dash exactly at x=480px and y=400px spot, during 8 frames, with delay of frames equals to 10. If you need to make it slower, change D and Delay to higher value, also you can reduce number of rames, or make them higher, script will automaticaly calculate velocities. So as for dash move i think it is solved.

Still the problem is to calculate Y velocity for leap move.
 
image.jpg


I think this can be a solution for finding Vy. You see Y is max height enemy is jumping with, and it is in the middle of the A root. X and Z are variables we are know, but to calculate A i need somehow to calculate square root from (X^2+Z^2)=(X*X+Z*Z)
Then it can be calculated like:
Vy=(A/2)/(Delay*(Frames/2))
Frames/2 is because it is a half of the root.
 
This script is great ! I was looking for it and i spent like 15 hours figuring out how to make enemy move to  X Z location precisely everytime and you did it ! ;D
Im using it for walk and it looks identical to some old games i remember, where delay stays the same and character moves to desired location, is it possible to make delay dynamic and keep numer of frames variable depending how far location is ? You know so walk feels more natural.
 
AFAIK the reason some games such as Punisher uses leap to defined coords instead of walk to is to control time used. By walking, since there's walking speed limit, it's hard to tell how long character would take to reach defined coords. Contrast to that, leaping allow character to reach the coords with single leap
I prefer to use the latter

If you insist in using walk to, I suggest looping the animation to allow character to take as many time as they needed to reach the coords
 
Bloodbane said:
I have function to make leap to defined coordinate and it was only used in pair with leap function. It was years ago and after some experience, I know that it can be used with dash function as well

Anyways, do you notice the basic difference between target and targetL function?
No, it's not "one for dash and the other for leap"! the basic difference is that target calculates required speed to get to target with defined maximum x and z speed while targetL calculates required speed with defined time to get to target.

Because of the latter, I can tell how much time required for targetting entity to reach target and thus I can tell them when to stop
And because of that function for leap/dash to defined position is based on targetL.

Let me find the one from Crime Buster for you but in mean time you can see this script:

Code:
@script
  if(frame==4){
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float Tx = openborvariant("xpos") + openborvariant("hResolution")/2;
    float Tz = (openborvariant("PLAYER_MIN_Z") + openborvariant("PLAYER_MAX_Z"))/2;
    float Vx;
    float Vz;

    Vx = (Tx-x)/66;
    Vz = (Tz-z)/66;

    tossentity(self, 3, Vx, Vz);
  }
@end_script

this script is used to make enemy jumps to center of playing field at frame 5. It jumps with 3 velocity so you can estimate that it will land about 60 centiseconds later

Bloodbane, did you create this script? I tweaked a bit and made it work for my mod, and I am planning to add a thank you note in the credits
 
Bloodbane said:
AFAIK the reason some games such as Punisher uses leap to defined coords instead of walk to is to control time used.
I know this but walk looks more natural, i already have your target and leap scripts and they work great but i wanted to have walk and the one from this topic works fantastic for pattern based attacks by enemies.
 
Is there any different between @cmd dash and @cmd dasher? I tried both xytarget and xyleap script and they're not working.
Bloodbane script is work though
 
dasher function is generic function to move entity, it can be set independently
dash function is function to move entity toward found target. It can't be set independently since it requires targetting function to be declared before that

Example:
Code:
anim attack3
	range	100 200
	rangez	-30 30
	delay	20
	offset	103 113
	bbox	58 73 103 40
	frame	data/chars/panther/charge1.png
	delay	10
	attack  111 67 57 45 18 1 0 0 30
	dropv	4 0 0
	@cmd	target 2.5 1.25 0 0 0 1
	@cmd	dash 0 0
	sound   data/sounds/jag.wav
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	delay	20
	attack  0
	@cmd	dasher 0 0 0
	frame	data/chars/panther/charge1.png

In this example, Panther targets player with target function right before dashing toward player with dash function. Then after it's done running, it stops with dasher function
 
Bloodbane said:
dasher function is generic function to move entity, it can be set independently
dash function is function to move entity toward found target. It can't be set independently since it requires targetting function to be declared before that

Example:
Code:
anim attack3
	range	100 200
	rangez	-30 30
	delay	20
	offset	103 113
	bbox	58 73 103 40
	frame	data/chars/panther/charge1.png
	delay	10
	attack  111 67 57 45 18 1 0 0 30
	dropv	4 0 0
	@cmd	target 2.5 1.25 0 0 0 1
	@cmd	dash 0 0
	sound   data/sounds/jag.wav
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	frame	data/chars/panther/run1.png
	frame	data/chars/panther/run2.png
	frame	data/chars/panther/run3.png
	frame	data/chars/panther/run4.png
	delay	20
	attack  0
	@cmd	dasher 0 0 0
	frame	data/chars/panther/charge1.png

In this example, Panther targets player right with target function before dashing toward player with dash function than after it's done running, it stops with dasher function
Ahh Thank you for this detailed explanation as well as answering my question why the script doesn't work because I only use the dasher function
 
Back
Top Bottom