Shooting in opposite/rear direction.

MysticalMist

Well-known member
I feel like I'm overlooking something very basic. But I'm currently relying on the @cmd projectile function so far.

Say I'm using this command:
Code:
@cmd projectile 1 "StrikerBullet" 62 0 63 1 0 0
but in the next frame, I want to use this command again to make the bullet aim and go towards the opposite direction.

What would be the easiest way to pull this off? Would I have to use the shooter function instead? I haven't coded in OpenBOR in a while, so I'll admit I've been very rusty.

UPDATE: I tried to use the shooter functions, however they don't really add to the player's score or show the enemy's health when it hits, and the speed is inconsistent.

Here is the header of the bullet the player is using:

Code:
name StrikerBullet
health 1
nolife     1
type none
subtype flydie
speed 35                   
shadow    0
subject_to_gravity 0
nolife  1
noquake    1                1
falldie    1                1
remove 1
subject_to_wall 1
offscreenkill 500
animationscript data/scripts/escript.c
 
Last edited:
Try using this function to shoot bullet backwards:
C:
void shooter3(void vName, float fX, float fY, float fZ, float Vx, float Vy, float Vz, int Dir)
{//Spawns projectile next to caller
 //vName: Model name of entity to be spawned in
 //fX : X location adjustment
 //fZ : Y location adjustment
 //fY : Z location adjustment
 //Vx : X speed
 //Vy : Y speed
 //Vz : Z speed
 //Dir : Direction

   void self = getlocalvar("self"); //Get calling entity
   int Direction = getentityproperty(self, "direction");
   void vSpawn; //Spawn object.
   int Arah = 0;

   vSpawn = spawn01(vName, fX, fY, fZ); //Spawn in projectile

   if(Dir == 1){
     Arah = Direction;
   } else if(Dir == -1){
     if(Direction == 0){
       Arah = 1;
     } else {
       Arah = 0;
     }
   }

   if(Direction == 0){ //Is entity facing left?                  
     Vx = -Vx; //Reverse Vx direction to match facing
   }

   changeentityproperty(vSpawn, "velocity", Vx, Vz, Vy);
   changeentityproperty(vSpawn, "direction", Arah);
   changeentityproperty(vSpawn, "speed", Vx);
   changeentityproperty(vSpawn, "owner", self);
}

For example, to shoot forward: @cmd shooter3 "Shot" 40 45 0 2 0 0 1
and to shoot backward: @cmd shooter3 "Shot" 40 45 0 -2 0 0 -1

"Shot" is just name sample. 40,45, 0 is just sample offset. The important setting is to shoot backward velocity needs to be negative and last parameter is set to -1.
 
Try using this function to shoot bullet backwards:
C:
void shooter3(void vName, float fX, float fY, float fZ, float Vx, float Vy, float Vz, int Dir)
{//Spawns projectile next to caller
 //vName: Model name of entity to be spawned in
 //fX : X location adjustment
 //fZ : Y location adjustment
 //fY : Z location adjustment
 //Vx : X speed
 //Vy : Y speed
 //Vz : Z speed
 //Dir : Direction

   void self = getlocalvar("self"); //Get calling entity
   int Direction = getentityproperty(self, "direction");
   void vSpawn; //Spawn object.
   int Arah = 0;

   vSpawn = spawn01(vName, fX, fY, fZ); //Spawn in projectile

   if(Dir == 1){
     Arah = Direction;
   } else if(Dir == -1){
     if(Direction == 0){
       Arah = 1;
     } else {
       Arah = 0;
     }
   }

   if(Direction == 0){ //Is entity facing left?                 
     Vx = -Vx; //Reverse Vx direction to match facing
   }

   changeentityproperty(vSpawn, "velocity", Vx, Vz, Vy);
   changeentityproperty(vSpawn, "direction", Arah);
   changeentityproperty(vSpawn, "speed", Vx);
   changeentityproperty(vSpawn, "owner", self);
}

For example, to shoot forward: @cmd shooter3 "Shot" 40 45 0 2 0 0 1
and to shoot backward: @cmd shooter3 "Shot" 40 45 0 -2 0 0 -1

"Shot" is just name sample. 40,45, 0 is just sample offset. The important setting is to shoot backward velocity needs to be negative and last parameter is set to -1.
Works well so far!

Only issue is that the projectiles do not "die"/get destroyed upon collision with a wall/barrier.
 
For that purpose, I use this script on the projectile:
C:
anim idle
@script
    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    int x = getentityproperty(self, "x");
    int y = getentityproperty(self, "y");
    int z = getentityproperty(self, "z");
    int C;

    if(Dir == 1){
      C = 6;
    } else {
      C = -6;
    }

    if(frame > 0 && y <= checkwall(x+C,z)){
      changeentityproperty(self, "velocity", 0, 0, 0);
      changeentityproperty(self, "subject_to_gravity", 1);
      changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
    }
@end_script
...

This script checks to find any wall in front of the projectile. If a wall is found and wall's height is higher or same as projectile's altitude, it will stop moving, allow itself to be affected by gravity and change animation to FOLLOW2.
BTW the entity using this script is thrown version of knife from DD Mini.
 
For that purpose, I use this script on the projectile:
C:
anim idle
@script
    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    int x = getentityproperty(self, "x");
    int y = getentityproperty(self, "y");
    int z = getentityproperty(self, "z");
    int C;

    if(Dir == 1){
      C = 6;
    } else {
      C = -6;
    }

    if(frame > 0 && y <= checkwall(x+C,z)){
      changeentityproperty(self, "velocity", 0, 0, 0);
      changeentityproperty(self, "subject_to_gravity", 1);
      changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
    }
@end_script
...

This script checks to find any wall in front of the projectile. If a wall is found and wall's height is higher or same as projectile's altitude, it will stop moving, allow itself to be affected by gravity and change animation to FOLLOW2.
BTW the entity using this script is thrown version of knife from DD Mini.


Ah, gotcha! Thank you!

P.S. love the module ngl
 
Back
Top Bottom