Solved Enemy character ascends to heaven

Question that is answered or resolved.

DD Tokki

Well-known member

The "wallbons" script effect causes enemies to bounce off walls when knocked down. I thought it was solved before, but there is one problem.
The player can move to both sides of the stage, and if the enemy leaves the screen while downed, they will ascend to the sky as shown in the video.

The script is like this:

C:
void main()
{
    wallBounce();
    wallUnlock();
}

void wallBounce()
{// Wall bounce on falling state
    void self = getlocalvar("self");
    int Vx = getentityproperty(self,"xdir");
    int Vy = getentityproperty(self,"tossv");
    int Vz = getentityproperty(self,"zdir");
    int Fall = getentityproperty(self, "aiflag", "drop");

    if(Fall==1){
      changeentityproperty(self, "velocity", -Vx*0.5, -Vz*0.5, Vy+1); // bounced
    }
}

void wallUnlock()
{//Unlock the screen edge (for enemies) according to defined animations
    void self    = getlocalvar("self");
    void type  = getentityproperty(self,"type");
    int anim    = getentityproperty(self, "animationID");

    if(type == openborconstant("TYPE_ENEMY")){
        if( anim == openborconstant("ANI_WALK")||
            anim == openborconstant("ANI_RUN")){
            changeentityproperty(self, "subject_to_screen", 0);
      }
   }
}

I would like to fix an issue with enemies ascending when they are off screen.
 

The "wallbons" script effect causes enemies to bounce off walls when knocked down. I thought it was solved before, but there is one problem.
The player can move to both sides of the stage, and if the enemy leaves the screen while downed, they will ascend to the sky as shown in the video.

The script is like this:

C:
void main()
{
    wallBounce();
    wallUnlock();
}

void wallBounce()
{// Wall bounce on falling state
    void self = getlocalvar("self");
    int Vx = getentityproperty(self,"xdir");
    int Vy = getentityproperty(self,"tossv");
    int Vz = getentityproperty(self,"zdir");
    int Fall = getentityproperty(self, "aiflag", "drop");

    if(Fall==1){
      changeentityproperty(self, "velocity", -Vx*0.5, -Vz*0.5, Vy+1); // bounced
    }
}

void wallUnlock()
{//Unlock the screen edge (for enemies) according to defined animations
    void self    = getlocalvar("self");
    void type  = getentityproperty(self,"type");
    int anim    = getentityproperty(self, "animationID");

    if(type == openborconstant("TYPE_ENEMY")){
        if( anim == openborconstant("ANI_WALK")||
            anim == openborconstant("ANI_RUN")){
            changeentityproperty(self, "subject_to_screen", 0);
      }
   }
}

I would like to fix an issue with enemies ascending when they are off screen.
I suggest you to use tossentity without Y velocity otherwise the character will be endlessly pushed to the top when close to the screen edge. And put into the onblocksscript event to work as soon as the character touches the screen edge.

C:
float xDir = getentityproperty(self, "xdir")/2; //CURRENT X VELOCITY HALVED
tossentity(self, NULL(), -xDir, 0); //APPLY THE OPPOSITE X VELOCITY HALVED

You can also check the character's Y position and disable the script below a certain limit. In addition, you don't need to always use xDir as reference, sometimes the character may fall without X axis velocity and the xDir will return zero.
In this case you can apply a fixed value for the X axis velocity, but don't forget to check the character's direction in order to apply the velocity to the correct side.
 
I suggest you to use tossentity without Y velocity otherwise the character will be endlessly pushed to the top when close to the screen edge. And put into the onblocksscript event to work as soon as the character touches the screen edge.

C:
float xDir = getentityproperty(self, "xdir")/2; //CURRENT X VELOCITY HALVED
tossentity(self, NULL(), -xDir, 0); //APPLY THE OPPOSITE X VELOCITY HALVED

You can also check the character's Y position and disable the script below a certain limit. In addition, you don't need to always use xDir as reference, sometimes the character may fall without X axis velocity and the xDir will return zero.
In this case you can apply a fixed value for the X axis velocity, but don't forget to check the character's direction in order to apply the velocity to the correct side.
thank you When I deleted "Vy+1" from the script, the rising phenomenon disappeared.
 
I've added vertical velocity change in the script with the assumption that bounced enemy won't immediately hit screen edge again.

If your enemies are only subject to screen in certain states (such as falling or knocked down), you can disable subject to screen after enemy is bounced once.
C:
void wallBounce()
{// Wall bounce on falling state
    void self = getlocalvar("self");
    int Vx = getentityproperty(self,"xdir");
    int Vy = getentityproperty(self,"tossv");
    int Vz = getentityproperty(self,"zdir");
    int Fall = getentityproperty(self, "aiflag", "drop");

    if(Fall==1){
      changeentityproperty(self, "velocity", -Vx*0.5, -Vz*0.5, Vy+1); // bounced
      changeentityproperty(self, "subject_to_screen", 0);
    }
}
 
I've added vertical velocity change in the script with the assumption that bounced enemy won't immediately hit screen edge again.

If your enemies are only subject to screen in certain states (such as falling or knocked down), you can disable subject to screen after enemy is bounced once.
C:
void wallBounce()
{// Wall bounce on falling state
    void self = getlocalvar("self");
    int Vx = getentityproperty(self,"xdir");
    int Vy = getentityproperty(self,"tossv");
    int Vz = getentityproperty(self,"zdir");
    int Fall = getentityproperty(self, "aiflag", "drop");

    if(Fall==1){
      changeentityproperty(self, "velocity", -Vx*0.5, -Vz*0.5, Vy+1); // bounced
      changeentityproperty(self, "subject_to_screen", 0);
    }
}
After testing, the player goes off screen on a fixed screen.
 
Oh, that means you'd need to set subject_to_screen 1 back in player's RISE animation.
If you want the player to move around the screen, you have to Rise once for the script effect to appear. I don't know how to create a script, so I think it would be difficult to implement it.
 
If you want the player to move around the screen, you have to Rise once for the script effect to appear.
in fact, no. You can change the subject_to_screen in your fall animation (I advice adding it on the landframe)

you have two options:

1- adding this function (works on OpenBOR 3) yo your animationscript
C-like:
void subjectScreen (int iG)
{
// controls the subject to screen
// Douglas Baldan/O Ilusionista
void self = getlocalvar("self");
changeentityproperty(self,"subject_to_screen",iG);
}

and call it on the frame you land
@cmd subjectScreen 1

or just an inline version on the same land frame:

Code:
@cmd changeentityproperty getlocalvar("self") "subject_to_screen" 1
 
in fact, no. You can change the subject_to_screen in your fall animation (I advice adding it on the landframe)

you have two options:

1- adding this function (works on OpenBOR 3) yo your animationscript
C-like:
void subjectScreen (int iG)
{
// controls the subject to screen
// Douglas Baldan/O Ilusionista
void self = getlocalvar("self");
changeentityproperty(self,"subject_to_screen",iG);
}

and call it on the frame you land
@cmd subjectScreen 1

or just an inline version on the same land frame:

Code:
@cmd changeentityproperty getlocalvar("self") "subject_to_screen" 1
Thanks, I'll try it.
 
in fact, no. You can change the subject_to_screen in your fall animation (I advice adding it on the landframe)

you have two options:

1- adding this function (works on OpenBOR 3) yo your animationscript
C-like:
void subjectScreen (int iG)
{
// controls the subject to screen
// Douglas Baldan/O Ilusionista
void self = getlocalvar("self");
changeentityproperty(self,"subject_to_screen",iG);
}

and call it on the frame you land
@cmd subjectScreen 1

or just an inline version on the same land frame:

Code:
@cmd changeentityproperty getlocalvar("self") "subject_to_screen" 1
For the player character, I applied the subjectscreen 1 script to the default behavior and it works well except for enemies.
 
Back
Top Bottom