Shoot Projectile Downwards

Aerisetta

Active member
Im using shooter script to shoot bullets. I want to be able to shoot some projectile downwards but for some reason it does not work. It can shoot upwards though. Can anyone see what's wrong?

example
@cmd shooter "bullene2" 210 120 1 18 2 4 (goes up)
@cmd shooter "bullene2" 230 120 1 18 4 2 (goes up)
@cmd shooter "bullene2" 220 120 1 18 0 0 (stays horizontal, ok)
@cmd shooter "bullene2" 240 120 1 18 -5 -2 (stays horizontal, wrong)
@cmd shooter "bullene2" 200 120 1 18 -10 -(stays horizontal, wrong)

The script
Code:
void shooter(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile with speed control
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;

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

   vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 1, 0, 0);
   changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   changeentityproperty(vShot, "speed", Vx);
}


The Bullet
Code:
name    bullene2
type    none
health  1
speed    200
noquake 1
remove    0
nolife  1

lifespan  3
candamage    enemy obstacle
offscreenkill     50
ondoattackscript data/scripts/variable_damage.c
animationscript        data/scripts/player.c


anim    idle
    forcedirection -1
    fastattack 1
    loop    1
    delay    3
    offset    39 55
    bbox    0 0 0 0
    hitfx    data/sounds/hitmarker2.wav
    hitflash    flash1
    attack20 22 23 35 50 8 0 0 0 0 25
    noreflect 1
    @cmd aniRandom openborconstant("ANI_FOLLOW1")
    frame    data/chars/misc/bullets/bullet01.gif

anim    follow1
    fastattack 1
    loop    1
    delay    3
    offset    39 55
    bbox    0 0 0 0
    drawmethod    tintmode 4
    drawmethod    tintcolor 255_0_0   
    hitfx    data/sounds/hitmarker2.wav
    hitflash    flash1
    attack20 22 23 35 50 10 0 0 0 0 25
    frame    data/chars/misc/bullets/bullet04.gif
 
@Aerisetta Usually when you spawn a projectile using the native projectile function the engine will change the original base to the current spawned height. To fix that you will need to reapply the base to zero in which is the default ground height, currently I'm using this method for Yamato stars.

C:
void shooter(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile with speed control
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;

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

   vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 1, 0, 0);
   changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   changeentityproperty(vShot, "speed", Vx);
   changeentityproperty(vShot, "base", 0); //BASE CONTROL
}
 
@Aerisetta Usually when you spawn a projectile using the native projectile function the engine will change the original base to the current spawned height. To fix that you will need to reapply the base to zero in which is the default ground height, currently I'm using this method for Yamato stars.

C:
void shooter(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile with speed control
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;

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

   vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 1, 0, 0);
   changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   changeentityproperty(vShot, "speed", Vx);
   changeentityproperty(vShot, "base", 0); //BASE CONTROL
}

Thanks!

I made yours a seperate shooter script called shooterdown though because for some reason it made all the bullets coming out with Vy = 0 drop as well (i want Vy = 0 to be just horizontal)
 
Thanks!

I made yours a seperate shooter script called shooterdown though because for some reason it made all the bullets coming out with Vy = 0 drop as well (i want Vy = 0 to be just horizontal)
Glad it works. As an alternative, instead of creating a separated script you can use an additional step only for the downward shots. In case you put negative values for Vy, the script will automatically apply the default base value.
I didn't test the code, please let me know in case you have issues.

C:
void shooter(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile with speed control
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;

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

   vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 1, 0, 0);
   if(Vy < 0){changeentityproperty(vShot, "base", 0);} //APPLY DEFAULT BASE VALUE FOR DOWNWARD SHOTS
   changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   changeentityproperty(vShot, "speed", Vx);
}
 
Back
Top Bottom