Hey guys im working on script that lets me add some pattern behaviour to characters, this one lets you set your coords and entity will walk towards them ,
When he will reach the coords then he will perform defined attack/ animation, it kinda works but not as good with Z axis.
Sometimes Z axis is screwed up and he walks towards lower location onscreen , i have direction both in stage so screen moves and i suspect this have something to do with it not working the same way all the time, can you give me a hint what to do to make it work nicely so he will reach the point ? Do i need additional detection of screen position?
Also in this script i only detect X and perform attack, because with x and z it doesnt work , Z axis isnt always the same but X is basically working right.
I would like him to reach 1000 450 and then stop,turn around towards player and perform attack2.
Did you guys tried something like this and got it working ?
When he will reach the coords then he will perform defined attack/ animation, it kinda works but not as good with Z axis.
Sometimes Z axis is screwed up and he walks towards lower location onscreen , i have direction both in stage so screen moves and i suspect this have something to do with it not working the same way all the time, can you give me a hint what to do to make it work nicely so he will reach the point ? Do i need additional detection of screen position?
Also in this script i only detect X and perform attack, because with x and z it doesnt work , Z axis isnt always the same but X is basically working right.
I would like him to reach 1000 450 and then stop,turn around towards player and perform attack2.
Code:
void targetxz(float Velx, float Velz, float Tx, float Tz , int Ani)
{// Targetting opponent before leaping or dashing
void self = getlocalvar("self");
int dir = getentityproperty(self, "direction"); // Get enemy's facing direction
float x = getentityproperty(self, "x"); // Get enemy's x coordinate
float z = getentityproperty(self, "z"); // Get enemy's z coordinate
setlocalvar("T"+self, findtarget(self)); // Find target and put it in local variable
float Vx = getentityproperty(self, "x"); // Attain x velocity
float Vz = getentityproperty(self, "z"); // Attain z velocity
if((dir==1) && ( Vx > Tx )){ // Are both velocity available?
changeentityproperty(self, "direction", 0); // Face left
changeentityproperty(self, "velocity", 0,0,0 );
performattack(self, openborconstant(Ani));
}
if((dir==0) && ( Vx < Tx )){ // Are both velocity available?
changeentityproperty(self, "direction", 0); // Face left
changeentityproperty(self, "velocity", 0,0,0 );
performattack(self, openborconstant(Ani));
}
if( getlocalvar("T"+self) != NULL()){ // Is there a target?
void target = getlocalvar("T"+self);
float Disx = Tx - x; // Get x distance
float Disz = Tz - z; // Get z distance
if(Disx < 0){ // Negative Disx?
Disx = -Disx; // Turn it to positive
changeentityproperty(self, "direction", 0); // Face left
} else {
changeentityproperty(self, "direction", 1); // Face right
}
if(Disz < 0){ // Negative Disz?
Disz = -Disz; // Turn it to positive
}
if(Disz < Disx) // Disx bigger than Disz?
{
if(Tx < x){ // Player is behind enemy?
setlocalvar("x"+self, -Velx); // Turn Vx to negative
} else { setlocalvar("x"+self, Velx); } // Use defined Vx
setlocalvar("z"+self, Velx*(Tz-z)/Disx); // Calculate Vz then store value in local variable
} else { // Disz bigger than Disx!
if(Tz < z){ // Player is behind enemy?
setlocalvar("z"+self, -Velz); // Turn Vz to negative
} else { setlocalvar("z"+self, Velz); } // Use defined Vz
setlocalvar("x"+self, Velz*(Tx-x)/Disz); // Calculate Vx then store value in local variable
}
} else { // No target at all!
setlocalvar("z"+self, 0); // 0 velocity
if(dir==0){ // Facing left?
setlocalvar("x"+self, -Velx); // Negative velocity
} else { setlocalvar("x"+self, Velx); } // Positive velocity
}
}
void dash()
{// Dash with previously attained speed!
void self = getlocalvar("self");
float Vx = getlocalvar("x"+self); // Attain x velocity
float Vz = getlocalvar("z"+self); // Attain z velocity
if( Vx!=NULL() && Vz!=NULL() ){ // Are both velocity available?
changeentityproperty(self, "velocity", Vx, Vz); //Move towards target!
}
}
Code:
anim attack4
loop 1
offset 90 177
bbox 59 30 65 148
delay 5
range 100 600
@cmd targetxz 3 3 950 480 "ANI_ATTACK2"
@cmd dash
frame data/chars/rocks/walk1.gif
frame data/chars/rocks/walk2.gif
frame data/chars/rocks/walk3.gif
frame data/chars/rocks/walk4.gif
frame data/chars/rocks/walk5.gif
frame data/chars/rocks/walk6.gif
frame data/chars/rocks/walk7.gif
@cmd targetxz 3 3 950 480 "ANI_ATTACK2"
frame data/chars/rocks/walk8.gif
frame data/chars/rocks/walk9.gif
frame data/chars/rocks/walk10.gif
frame data/chars/rocks/walk11.gif
frame data/chars/rocks/walk12.gif
frame data/chars/rocks/walk13.gif
frame data/chars/rocks/walk14.gif
frame data/chars/rocks/walk15.gif
frame data/chars/rocks/walk16.gif
Did you guys tried something like this and got it working ?