flying enemys

Gurtag

Member
how could be set an enemy so it can fly/float i mean that can move freely up, down and attack no matter it´s spawn altitude, i tryed with antigravity 100 and subject-togravity 0 but it stays stationary like been freezed
 
To set floating/flying enemy, you need to set seta in his/her animations. You don't need to set antigravity anymore as the enemy will stay in defined altitude. The only time you need to play with antigravity is when the enemy is diving or changing altitude briefly

If you need example, you can examine Jetpack subbosses from Crime Busterv2.5 or harpies from Map demo. Here's link for Map demo: https://www.mediafire.com/?mivsls5mb8988b9

In map demo, go to mountains to find some harpies
 
i will check it out, thanks to your imput and scripts got my climb level working like a charm, however i am kind of stuck about this flying enemy i want to implement, seta would make it stay at a defined altitude but wont move up or down to chace player, i want it to move like if z were all walkable area so it can chace me to all parts of the climb level regardless of altitud, platforms and such, will also check out your contra mod, i remeber it had some flying insects enemys very simal to what i want to achive, though if they have some script imvolved i might get back to bug you  :P
 
Ah I see

First of all, enemy AI is for xz plane and it only works on ground. So making them afloat with antigravity causes enemies not to do anything.
That's why for flying enemies which works in 2D levels, I scripted their AI myself

Here's chasing flying enemy from Robo Magi, I'm working on:
Code:
name    	Rarad
health  	5
nomove  	1 1
type		enemy
cantgrab 	1
nodrop  	2
death   	1
nopain  	1
nolife  	1
subject_to_gravity 0
subject_to_platform 0
offscreenkill	3000
diesound	data/sounds/botdie.wav
animationscript  data/scripts/enemy.c
takedamagescript data/scripts/blink.c
alternatepal	data/chars/jylo/blink.png
alternatepal	data/chars/jylo/map1.png
alternatepal	data/chars/jylo/map2.png
alternatepal	data/chars/jylo/map3.png


anim	idle
	loop	1
	delay	6
	offset  24 35
	bbox 	9 9 32 25
	attack	9 9 32 25 5 1 1 1
	frame   data/chars/jylo/rarad1.png
	@cmd	target 0.8 0.8 0 -10 1 0
	@cmd	dash 0 0
	frame   data/chars/jylo/rarad2.png
	frame   data/chars/jylo/rarad3.png
	@cmd	target 0.8 0.8 0 -10 1 0
	@cmd	dash 0 0
	frame   data/chars/jylo/rarad2.png #
	frame   data/chars/jylo/rarad1.png
	@cmd	target 0.8 0.8 0 -10 1 0
	@cmd	dash 0 0
	frame   data/chars/jylo/rarad2.png
	frame   data/chars/jylo/rarad3.png
	attack	0
	@cmd	target 0.8 0.8 0 -10 1 0
	@cmd	dash 0 0
	frame   data/chars/jylo/rarad2.png #

anim	spawn
	delay	6
	offset  24 35
	frame   data/chars/jylo/rarad1.png
	frame   data/chars/jylo/rarad2.png


anim	death
	delay	10
	offset  24 35
	frame   data/chars/jylo/raradD.png
	frame	data/chars/misc/empty.gif
	frame   data/chars/jylo/raradD.png
	frame	data/chars/misc/empty.gif
	frame   data/chars/jylo/raradD.png
	@cmd	dropperI 0 20
	frame	data/chars/misc/empty.gif
	frame   data/chars/jylo/raradD.png
        @cmd    suicide
	frame	data/chars/misc/empty.gif

The scripts in IDLE are the ones moving Rarad to chase player
Here are the functions (long codes warning):
Code:
void target0(float Velx, float Vely, float Tx, float Ty, float dx, float dy, void Vel, int Flip)
{// Basic Targetting certain coordinate before dashing
// Velx = Desired x Velocity
// Vely = Desired y Velocity
// Tx = target x coordinate
// Ty = target y coordinate
// dx = x added distance
// dy = y added distance
// Vel = Desired output

    void self = getlocalvar("self");
    int dir = getentityproperty(self, "direction");
    float x = getentityproperty(self, "x");
    float y = getentityproperty(self, "a");
    float Vx;
    float Vy;

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

    x = x+dx;
    y = y+dy;
    float Disx = Tx - x;
    float Disy = Ty - y;

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

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

// Calculate velocity for targetting
    if(Disy < Disx)
    {
      if(Tx < x){
        Vx = -Velx;
      } else { Vx = Velx; }

      Vy = Velx*(Ty-y)/Disx;
    } else {
      if(Ty < y){
        Vy = -Vely;
      } else { Vy = Vely; }

      Vx = Vely*(Tx-x)/Disy;
    }

    if(Vel == "x"){
      return Vx;
    }
    if(Vel == "y"){
      return Vy;
    }
}

void target1(void Target, float Velx, float Vely, float dx, float dy, int Stop, void Vel, int Flip)
{// Targetting certain entity before dashing
// Target = Targetted entity
// Velx = Desired x Velocity
// Vely = Desired y Velocity
// dx = x added distance
// dy = y added distance
// Stop = flag to stop moving if there's no target

    void self = getlocalvar("self");
    int dir = getentityproperty(self, "direction");
    float x = getentityproperty(self, "x");
    float y = getentityproperty(self, "a");
    float Vx;
    float Vy;

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

    if( Target != NULL()){
      float Tx = getentityproperty(Target, "x");
      float Ty = getentityproperty(Target, "a");

      Vx = target0(Velx, Vely, Tx, Ty, dx, dy, "x", Flip);
      Vy = target0(Velx, Vely, Tx, Ty, dx, dy, "y", Flip);
    } else {
      if(Stop == 1){
        Vy = 0;
        Vx = 0;
      } else if(Stop == 2){
        Vy = NULL();
        Vx = NULL();
      } else {
        Vy = 0;
        if(dir==0){
          Vx = -Velx;
        } else { Vx = Velx; }
      }
    }

    if(Vel == "x"){
      return Vx;
    }
    if(Vel == "y"){
      return Vy;
    }
}

void target(float Velx, float Vely, float dx, float dy, int Stop, int Flip)
{// Targetting opponent before leaping or dashing.
// Velx = x Velocity
// Vely = y Velocity
// dx = x added distance
// dy = y added distance
// Stop = flag to stop moving if no target is found

    void self = getlocalvar("self");

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

    void target = getlocalvar("T"+self);
    setlocalvar("x"+self, target1(target, Velx, Vely, dx, dy, Stop, "x", Flip) );
    setlocalvar("y"+self, target1(target, Velx, Vely, dx, dy, Stop, "y", Flip) );
    setlocalvar("T"+self, NULL()); //Clears variable
}

void dash(int X, int Y)
{// Dash with previously attained speed!
    void self = getlocalvar("self");
    float Vx = getlocalvar("x"+self);
    float Vy = getlocalvar("y"+self);

    if( Vx!=NULL() && Vy!=NULL() ){
      if( X==1 ){
        Vy = 0;
      } else if( Y==1 ){
        Vx = 0;
      }

      changeentityproperty(self, "velocity", Vx, 0, Vy);
    }
}

If you want, you can download that mod and copy the script libraries to get complete set
 
awsome man, works very nice, however what the parameters do? i asume they control movement but cant seem to find the right spot, also i put nomove 1 1 but the entity doesnt turn around for some reason
 
Glad to hear it working

As for parameters, let's start from this function:
Code:
target(float Velx, float Vely, float dx, float dy, int Stop, int Flip)

Example:
@cmd target 1 1 0 -10 1 1

1 1 means entity moves at maximum velocity 1 pixel per centisecond in x or y axis

0 -10 means entity targets 0 pixels in x and 10 pixels in y relative to player or targetted opponent. These parameter will be important if say the enemy is quite large and you want it to hit its beak/claw instead of its body

1 means entity will stop if no target is found

1 means entity will flip toward target if target is behind entity

Next function
Code:
void dash(int X, int Y)

Ex: @cmd dash 0 0

0 0 means entity will move in both x and y axis to chase target

also i put nomove 1 1 but the entity doesnt turn around for some reason

Setting nomove 11 causes entity not to turn toward opponent
OTOH flying enemies won't turn toward opponent on its own anyways that's why I use target function above to turn enemies toward player
 
work like a charm and turns around now, i owe you my sister  :P btw i am creating several visual effects like smoke trails and the like, the thing is i dont allways need to bind those entities, however if i use a simplier spawnscript or spawnframe i must allways create a new entity since spawn or idle would be the only used anims, i wanted to ask if there is a spawnscript that works like spawnbind by using same anim as spawner but with out binding/moving with the spawner entity, that would save from creating several entities for each effect and be more eficient.
 
hey man and thanks but i allready got the trail effect right, let me see if i can explain better, i use spawnscript to spawn  an x entity on subzero attack1 and i also need the spawned entity to spawn on it´s attack1 anim, but i dont want to bind it to sub zero, just spawn on the same anim as spawner, have several effects that dont require to be binded but would be useful to still be able to spawn them on the same anim as spawner, that way i would use one entity for various effect instead of creating entitys for each one of them.
 
This is what I does with Iron Fist - I have an entity for all his effects. In some cases, the effect is binded to the spawner, in some cases not.
Its very useful for this situation.

The only thing you can't do is to make an entity to spawn a copy of itself. There is a protection about this on the core code.
A former dev told me there is a way to bypass it, but he never explained neither any other, so we can't do it.

It would be very useful.
 
copy of itself ? indeed would be very usefull, but you can still fake it with entity i gess? anyway thanks a lot for the info man, will take a closer look now. also sorry if i bug around with so much questions but i am having some litle trouble with obstacles/platforms and dont know if it is normal behavior or a bug, the thing is that when i set platform on a obstacle, its blocking physics become inconsistent, it sometimes block player movement it somethimes dont and you can get inside the obstacle or pass it trough.
 
Yes, one entity can not spawn a copy of itself. For example, if you have an entity called Bob and try make it call himself, strange behaviours can happen - at least, with script.

No need to be sorry, we are here to help.

About the obstacle/platforms, it's better to open a new topic. And tag Magggas on it, he is pretty skilled with it.
 
Gurtag said:
the thing is that when i set platform on a obstacle, its blocking physics become inconsistent, it sometimes block player movement it somethimes dont and you can get inside the obstacle or pass it trough.

Post the whole text of that obstacle here so we can see what's wrong :)
 
here ya go

Code:
name    prey
type    obstacle
shadow  0
gfxshadow  1
health  2020
diesound  data/chars/guard/fall.wav
nolife  1
flash   eflash
noatflash 1
offscreenkill  2000
nodieblink      3

palette data/sprites/aniback/hea1.gif
alternatepal    data/sprites/aniback/maprojo.gif
alternatepal    data/sprites/aniback/mapverde.gif
alternatepal    data/sprites/aniback/asulmap.gif
alternatepal    data/sprites/aniback/freeze.gif
fmap 4

load    full_health



anim	death
	loop	0
	delay	9
	offset	102 150
	frame	data/sprites/aniback/hea1p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea2p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea3p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea33p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea2p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea3p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea2p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea3p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea33p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea2p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea3p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea33p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea2p.gif
	sound	data/sounds/he1.wav
	frame	data/sprites/aniback/hea4p.gif
	frame	data/sprites/aniback/hea5p.gif
	delay	8
	offset	78 140
	sound	data/sounds/pitfall2.wav
	frame	data/sprites/aniback/br1.gif
	frame	data/sprites/aniback/br2.gif
	frame	data/sprites/aniback/br3.gif
	frame	data/sprites/aniback/br4.gif
	frame	data/sprites/aniback/br5.gif
	frame	data/sprites/aniback/br5.gif
	frame	data/sprites/aniback/br5.gif
	frame	data/sprites/aniback/br5.gif
		
anim	idle
	loop	1
	subentity	Full_Health
	summonframe	2 -4 -4 0 0
	platform	102 150 -24 -24 24 24 50 78
	delay	12
	bbox	26 49 94 101
	offset	102 150
	frame	data/sprites/aniback/hea11.gif
	frame	data/sprites/aniback/hea22.gif
	frame	data/sprites/aniback/hea33.gif
	frame	data/sprites/aniback/hea44.gif
	frame	data/sprites/aniback/hea33.gif
	frame	data/sprites/aniback/hea22.gif
		
#|edited by openBor Stats v 0.53



here a litle video showing what i mean.




this behavior doesnt ocur with out platform set on the obstacle, however i am working on a 2d climb level and if i dont set platform, the obstacle blocks movement at all heights of the level.
 
Oh yes, about the obstacles, if you don’t set a platform on them you can’t jump/pass through above then at any hight. So in order to also control how high they can block the path we always had to add a platform on them. Not sure if that was a bug or normal but it was always like that. So as is is, for a 2d level they must have a platform on them.
 
Just for the record, that is intentional behavior. It simplifies making obstacles like log jams and whatnot that are meant to be impassible.

DC
 
sup guys, and yea i get the obstacle part, but i thought platform worked the same but restricting the blocade/collision part to platform box coordinates, check the video, i can get inside/passtrough it, that is what i meant if it was normal behavior, i mean, i thought seting platform would allow me to jump over it, not get inside it.
 
Ah okay, this is normal too. No matter what the bbox of the obstacle is, once you will setup a platform on it then the platform overwrite the the bbox and it’s “blocking” functionality. Then it’s just a matter of setting the platform correctly. If not, then yes, things like in your video can happen.
 
Back
Top Bottom