Help with entity walk limit y axis.

kdo

Member
Is there any way to limit how far a certain entity can walk on the Y axis?
I want to make a biker subtype entity walk only on the street part of the stage and not walk on the sidewalk. The player can walk everywhere.
Sem Título-1.png

In the image the green part shows the limit where the biker can go and the blue part shows the area the player can walk through.
 
Solution
@kdo: Here's a quick sample of what I'm talking about:
Code:
name             BikerC
type             none
gfxshadow        1


anim    idle
@script
  void self = getlocalvar("self"); //Get calling entity.
  int Dir = getentityproperty(self, "direction");
  int x = getentityproperty(self, "x");
  int Vx = getentityproperty(self, "xdir");
  int XPos = openborvariant("xpos"); //Get screen edge's position
  int Screen = openborvariant("hResolution"); // Get screen width

  if(x >= XPos + Screen + 160 && Dir==1){
    changeentityproperty(self, "position", NULL(), 240);
    changeentityproperty(self, "velocity", -Vx);
    changeentityproperty(self, "direction", 0);
  } else if(x <= XPos - 160 && Dir==0){
    changeentityproperty(self...
By creating a script and picking z value from the entity itself
Code:
void main(){
    void self = getlocalvar("self");
       int z = getentityproperty(self, "z") - openborvariant("ypos");//Y position of the entity
       
       if(z < 170){ // if entity reach certain Y position
           changeentityproperty(self, "velocity", 0,2,0); //force entity to move down to stay in line, Velocity uses X Z A parameters
       } else if(z > 191){ //if entity reach certain Y position
           changeentityproperty(self, "velocity", 0,-2,0); //force entity to move up to stay in line
       }
}
}
it will force the entity to stay in the limits,i tried my best to keep the test entity on the lines but it isn't perfect, you create a .c file and put the code in there,name it anything you want and on entity's header do this(i don't know what exact header you have on such entity so this is a example)
Code:
name Biker
health ...
speed ...
script data/[folder you put such script]/[scriptname].c
then the script will be working since entity is activated,remember to change z number condition to exact z your stage have(since my stage i used 170 and 191 but you need to change it for your stage)and then it will be working good,remember that this script will always activate anytime so if you want i can do one that you can activate and disactivate this limitation
 
The biker is Just passing, its no need to chase the player, its just works like a background element.

You just need spawn the bike and use dasher function to get bike move horizontal
something like this:
Code:
name     Darkgreencar
type     none
shadow     0
offscreenkill 1500
//setlayer -15
animationscript        data/scripts/cbusters.c




anim    idle
    loop    1
    delay    12
    offset    0 163
    @cmd     dasher 1 0 0
    sound    data/sounds/car_horn_2.wav
    frame    data/Bgs/Mission_Start/greenc2.gif
    frame    data/Bgs/Mission_Start/greenc1.gif
    frame    data/Bgs/Mission_Start/greenc2.gif
    frame    data/Bgs/Mission_Start/greenc3.gif

in my case I put dasher in animation script
Code:
void dasher( float Vx, float Vy, float Vz )
{// Dash with desired speed!
    void self = getlocalvar("self");
    int dir = getentityproperty(self,"direction");

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

    changeentityproperty(self, "velocity", Vx, Vz, Vy); //Move!
}

or just use openbor move feature so you don't need to use any script
Code:
move {x}

    Starting with the next frame, the entity will move forward (x) pixels with every new frame.
    This value must be set to 0 again to stop the entity from moving any further during the animation.
    You can use a negative value for (x) to move the entity backwards (Or slow their movement if they move automatically, like a jump attack).
    Somewhere above 200, this value will allow an entity to run offscreen, out of play, and into oblivion. If you want to get rid of an entity, this should fit the bill, but otherwise you'll have a suicidal entity. If you ARE trying to kill something, use a value like 1000, just in case.
 
@Steve Craft , i tried your script but engine chrashes, log info is " Failed to parse script file: 'data/scripts/cars.c'! " , iam using a old engine version to port the game to retro consoles, maybe this engine version doesnt suport your script or i've made something wrong.
In entity header i put this line:

script data/scripts/cars.c

And a made a cars.c file with the code.
 
@machok i tried your idea with @cmd dasher, but it works only one time, the biker keeps passing right to left and left to right forever, this is what i need but in the corret position.
The move command doesnt wok to limit the entity movement, it work to move the entity pixel per pixel at some axis. Doesnt work for me but its a great function....thank you!!!
 
You know kdo, for this kind of biker and road design, I suggest using simple entity and code it to move left or right and return if has gone offscreen. While returning, z position is also changed.
 
@Steve Craft , i tried your script but engine chrashes, log info is " Failed to parse script file: 'data/scripts/cars.c'! " , iam using a old engine version to port the game to retro consoles, maybe this engine version doesnt suport your script or i've made something wrong.
In entity header i put this line:

script data/scripts/cars.c

And a made a cars.c file with the code.
I used one of the lastests versions for the code(i don't have a console that's compatible with openbor to test it so i normally just do for PC) and for what i tested here if the code was write wrong it would only crash while running the stage that the entity is and the error would be not that one you got, so maybe it's the old engine version

The biker is Just passing, its no need to chase the player, its just works like a background element.
On this case Z position would simply work to change the position instead of forcing it to move to inside limits,i can try to make such script but i fear that it can also cause same error as before
 
@kdo: Here's a quick sample of what I'm talking about:
Code:
name             BikerC
type             none
gfxshadow        1


anim    idle
@script
  void self = getlocalvar("self"); //Get calling entity.
  int Dir = getentityproperty(self, "direction");
  int x = getentityproperty(self, "x");
  int Vx = getentityproperty(self, "xdir");
  int XPos = openborvariant("xpos"); //Get screen edge's position
  int Screen = openborvariant("hResolution"); // Get screen width

  if(x >= XPos + Screen + 160 && Dir==1){
    changeentityproperty(self, "position", NULL(), 240);
    changeentityproperty(self, "velocity", -Vx);
    changeentityproperty(self, "direction", 0);
  } else if(x <= XPos - 160 && Dir==0){
    changeentityproperty(self, "position", NULL(), 180);
    changeentityproperty(self, "velocity", -Vx);
    changeentityproperty(self, "direction", 1);
  }
@end_script
    loop    1
    delay    5
    offset    61 100
    frame    data/chars/biker/biker.gif
        frame    data/chars/biker/biker2.gif
        frame    data/chars/biker/biker3.gif
    frame    data/chars/biker/biker.gif
        frame    data/chars/biker/biker2.gif
        frame    data/chars/biker/biker3.gif
    frame    data/chars/biker/biker.gif
        frame    data/chars/biker/biker2.gif
        frame    data/chars/biker/biker3.gif

anim    spawn
@script
  if(frame==1){
    void self = getlocalvar("self"); //Get calling entity.
    int Dir = getentityproperty(self, "direction");

    if(Dir==1){
      changeentityproperty(self, "velocity", 1);
    } else {
      changeentityproperty(self, "velocity", -1);
    }
  }
@end_script
    delay    5
    offset    61 100
    sound    data/sounds/bike.wav
    frame    data/chars/biker/biker.gif
        frame    data/chars/biker/biker2.gif
        frame    data/chars/biker/biker3.gif

This biker uses biker sprites from Beats of Rage so you know how to get the sprites.
Anyways, this biker moves to one direction then if it's 160 pixels offscreen, it will flip to opposite direction and goes to specific z coords. If it's offscreen right, it will flip to left on z = 240 and if it's left, flip to right on z = 180.

I prefer not to randomize the z coords cause on roads like in image above, vehicles move on lanes with certain direction.
But of course, the script could be modified to randomize z coords a bit and change flipping condition to offscreen to off level. Off level means outside the level whose size is defined by panel size.
 
Solution
@Bloodbane , i've tried your script but the entity is apawned and go left out of the screen and dont flip and come back.
Seems like it just perform the spawn animation.
Take a look at my entity flag.

name car
type none
health 9999

Speed 8

anim idle

@script
void self = getlocalvar("self"); //Get calling entity.
int Dir = getentityproperty(self, "direction");
int x = getentityproperty(self, "x");
int Vx = getentityproperty(self, "xdir");
int XPos = openborvariant("xpos"); //Get screen edge's position
int Screen = openborvariant("hResolution"); // Get screen width

if(x >= XPos + Screen + 160 && Dir==1){
changeentityproperty(self, "position", NULL(), 240);
changeentityproperty(self, "velocity", -Vx);
changeentityproperty(self, "direction", 0);
} else if(x <= XPos - 160 && Dir==0){
changeentityproperty(self, "position", NULL(), 180);
changeentityproperty(self, "velocity", -Vx);
changeentityproperty(self, "direction", 1);
}
@end_script
loop 1
offset 40 45
delay 12

frame data/npcs/car/c.png
frame data/npcs/car/c2.png
frame data/npcs/car/c3.png
frame data/npcs/car/c4.png
frame data/npcs/car/c5.png
frame data/npcs/car/c6.png

anim spawn
@script
if(frame==1){
void self = getlocalvar("self"); //Get calling entity.
int Dir = getentityproperty(self, "direction");

if(Dir==1){
changeentityproperty(self, "velocity", 1);
} else {
changeentityproperty(self, "velocity", -1);
}
}
@end_script

offset 40 45
delay 12

frame data/npcs/car/c.png
frame data/npcs/car/c2.png
frame data/npcs/car/c3.png
frame data/npcs/car/c4.png
frame data/npcs/car/c5.png
frame data/npcs/car/c6.png
 
Last edited:
I removed the speed 8 in the header, but didnt work, the entity moves from the right to the left and get out of the screen and dont come back.
Is my header wrong?
 
Back
Top Bottom