Help with runner/ biker enemy!

kdo

Member
Hello guys, i need some help here please...

I trying to create an enemy that stay allways running inside 2 walls/platform, right to left, left to right , its in a 2d level, like Marios enemy that keeps walking and when it  hits the wall turn back and keep walking antill hit another wall.

I tried to use subtype biker, it would be te perfect behaviour, but  the biker pass through the platform an go out the screen even with 

subject_to_wall 1, subject_to_platform 1 or subject_to_screen 1.

Any ideia ?  :-[ thanks...


 
I think you can try a trick and use the EDGE animation:

EDGE {players} (6330+)

Optional.
This animation is played when the player is on the edge of walls, platforms and holes, as if trying to balance so as not to fall.

On that animation, you use a flipframe to make it to turn around...and it should be walking from one side to another.

But I don't know if this animation will work for non-players. If not, you can try to use the same approach with WALKOFF anim, but you will need to adjust the velocity for that.
 
And this is what you need i think

Code:
wall bump and turn

@script
    void self = getlocalvar("self");
    int x = getentityproperty(self, "x");
    int z = getentityproperty(self, "z");
    int Dir = getentityproperty(self, "direction");
	int sped = getentityproperty(self, "speed");
    int Sx = 1;
if(Dir==0){
     Sx = -Sx;
	 changeentityproperty(self, "velocity", 0-sped );
    }
if(Dir==1){
	 changeentityproperty(self, "velocity", sped );
    }
    void Plat = checkwall(x+Sx, z);
if( Dir == 0 && frame > 0 && x-(x-Plat) > 20 ){ 
     changeentityproperty(self, "direction", 1 );
    }
if( Dir == 1 && frame > 0 && x-(x-Plat) > 20 ){ 
    changeentityproperty(self, "direction", 0 );
     }
@end_script
As the name says wall bump and turn , then walk opposite.
I have this other one  too, make enemy move from left to right on platform, in a loop i need to modify it to take platform length into  calculations
I think its this one, its 40 pixels left/righ from the offset of the platform but in other scripts i use aggression to give platform entity its length for scripts.
So you would have to getentity property aggression and  change x+40 to  x+aggresion/2 and x-aggression/2  assuming platform is 80 pixels long
Code:
@script
    void self = getlocalvar("self");
    int x = getentityproperty(self, "x");
    int z = getentityproperty(self, "z");
    int y = getentityproperty(self, "a");
    int Dir = getentityproperty(self, "direction");
	int sped = getentityproperty(self, "speed");
	 void  Plat = checkplatformbetween(x, z, 0, 1000);
if(Dir==0){
  changeentityproperty(self, "velocity", -1  ,0,0);
    }
if(Dir==1){
  changeentityproperty(self, "velocity", 1  ,0,0);
    }
	if(Dir==0 && x+40 <= getentityproperty(Plat, "x")){
	  changeentityproperty(self, "direction", 1 );
    }
		if(Dir==1 && x-40 >= getentityproperty(Plat, "x")){
	  changeentityproperty(self, "direction", 0 );
    }
@end_script


--
-OK heres modified platform one with health, you would have to give platform entity health the same as length , this way you can control its length from level by giving different health as well .

Code:
@script
    void self = getlocalvar("self");
    int x = getentityproperty(self, "x");
    int z = getentityproperty(self, "z");
    int y = getentityproperty(self, "a");
    int Dir = getentityproperty(self, "direction");
	int sped = getentityproperty(self, "speed");
    void  Plat = checkplatformbetween(x, z, y-100, 200);
if(Dir==0){
  changeentityproperty(self, "velocity", -1  ,0,0);
    }
if(Dir==1){
  changeentityproperty(self, "velocity", 1  ,0,0);
    }
	if(Dir==0 && x+getentityproperty(Plat, "health")/2+2 <= getentityproperty(Plat, "x")){
	  changeentityproperty(self, "direction", 1 );
    }
		if(Dir==1 && x-getentityproperty(Plat, "health")/2-2 >= getentityproperty(Plat, "x")){
	  changeentityproperty(self, "direction", 0 );
    }
@end_script
 
kdo, I don't suggest using biker for that purpose

I've made scripts for that purpose in Cherry On Top and Robo Magi . For more information, you can read further in this thread

[A Day later]

You can download those 2 games if you want to see examples.
However I decided to create simple demo to show those scripts which can be downloaded here
Please read note.txt to understand which script is used for what purpose

HTH
 
Thanks for the help... :)

I tried the scripts but didnt work for me...
So i though something withou scrips to solve the problem.

I solved it, but probably with the worst way.
I created a entity that no move, its ofset is fixed in the midle of the walkable area
but the sprites of walk animation cover the size of walkable area, the entity walk
animation is the same size of the platform.
Its looks noob, but works... :-[
 
Scripts work fine, You just have to  modify them for your case.
Your walls are walls or platforms ? I posted code for platforms,  but i guess i could modify it for walls
bloodbane is using onblockscripts and im using one animation to make it compact but his method is how it should be done the right way.
Buf it my method works without issues then nobody cares but coders themselves, for me priority is compact code > proper structure.
 
bWWd said:
Buf it my method works without issues then nobody cares but coders themselves, for me priority is compact code > proper structure.

Be careful doing that bWWd. Us coder types aren't trying to make you do it our way for no reason. Making code more compact almost always makes it less optimal. Code is for humans, it's not what the machine sees when it is compiled and used. The sheer volume of code has absolutely nothing to do with how optimal it is, and in fact compacting code tends to make it far less efficient for the machine to run. What matters is the work being done, the type of work you do, and how it's organized.

I'm not saying you are doing anything wrong, maybe that's just how you like things to look in your module or whatever and that's cool. But if you are trying to keep your codebase smaller thinking it will run better, you are almost certainly having the opposite effect.

DC
 
I agree, maybe with time i will switch to event scripts.
For now i do it this way cause i have a big txt file with most of my scripts in there for different scenarios, i use event scripts when other ways fail.
 
kdo said:
I tried the scripts but didnt work for me...

:(
What exactly do you mean by not working?
If you want enemies to bounce off or rather turns around after blocked by wall or platform, you need to use onblockwscript and onblockpscript, like this:
Code:
onblockpscript	data/scripts/pantul.c
onblockwscript	data/scripts/pantul.c

You can find pantul.c script in demo I've posted above :)
 
Sorry Bloodbane, dont get me wrong, probably  the script didnt work for me because i made something wrong when i tried to use it.
I'll try the lines you send me above.

Thanks... ;)
 
Back
Top Bottom