• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Throwing/Shooting Knives/Projectiles

Throwing/Shooting Knives/Projectiles By Bloodbane ;D

Intro: I'm sure all of you have seen characters who can shoot projectiles in brawler games. The projectiles varies from knives, grenades, stars, rocks, bullets to bombs and laser shots. They are also shot in various ways i.e thrown, shot, tossed etc. This tutorial will explain how to set projectile shooting. OpenBoR supports 3 ways of shooting projectile:
1. Throwing knife (Projectile flies straight forward)
2. Throwing stars (Projectile falls down)
3. Tossing bombs (Projectile flies in arc)
This section explains about 'Throwing knife'. Oh, despite of the name, you can use missiles, bullets or anything else aside of knife. Also, the knife can also be thrown on ground turning it into shot.
Before I start, I must imply that character and projectile are 2 DIFFERENT entities. That means, you need to make another entity for the projectile.
Also, this method is applicable for any kind of entities so no need to check character's type.

Procedure: Like said before, projectile is another entity so let's make one like this example:


Code:
name Bullet
speed 30
type none
shadow 0

anim idle
delay 100
offset 5 3
attack 0 0 10 6 10 1
frame data/chars/misc/bullet.gif

This text is for Bullet projectile. Speed determines how fast it flies forward, type is not important but let's choose 'none', shadow is set 0 so it won't cast shadow but it's optional.
Bullet only has IDLE animation but it's enough cause it won't play other animation (except under special settings). In this animation, aside from common commands (frame,offset,delay), there's attackbox. This attackbox determines the attacking properties of this projectile. IOW when this projectile is fired or thrown, it's already attacking.
Bullet can have animated IDLE animation, looping, multiple hits etc like normal attack animation. However, unlike normal entity, this projectile dies after it hits anything.

Since it's an entity, it must be declared in models.txt:


know Bullet data/chars/misc/bullet.txt

Actually, it can be declared with 'load' but let's choose 'know' cause this projectile will be 'loaded' by the character who's throwing it. To load it like that simply declare this command in respective character's text header.


load Bullet

When the character is loaded, Bullet will also be loaded together. After that, we need to set Bullet as this character's knife like this:


knife Bullet
To throw this Bullet, character must use 'throwframe'. The command must be declared in desired animation like this example:


Code:
anim attack1
range 60 200
delay 6
offset 40 115
throwframe 3 82
bbox 20 9 36 102
frame data/chars/topan/shoot01.gif
bbox 26 9 34 102
frame data/chars/topan/shoot02.gif
delay 10
bbox 31 9 34 102
frame data/chars/topan/shoot03.gif
delay 15
sound data/sounds/dor2.wav
frame data/chars/topan/shoot04.gif
delay 6
frame data/chars/topan/shoot03.gif
bbox 26 9 34 102
frame data/chars/topan/shoot02.gif
bbox 20 9 36 102
frame data/chars/topan/shoot01.gif

'Throwframe 3 82' means Bullet is thrown at 4th frame at 82 pixels high from character's altitude. Yes, it's relative to character instead of to ground. That means if the character is jumping while throwing, thrown projectile will start high.
You can declare 'throwframe' in other animations too but only one 'throwframe' per animation.

Extra: There are extra commands that you can add to modify both projectile and shooting animation. For projectile some of them are:
- hitenemy (to control which other entities this projectile can hit)
- candamage (to control what type this projectile can hit)
- remove (to set if this projectile dies on hit or continue flying after hit)
- lifespan (to control how long this projectile lives)
- nomove (to make static projectile)

All of them are declared in projectile's text header if you use them.
Although all mentioned above are optional, it's recommended to declare 'candamage' to ensure the projectile can hit desired entity.
Aside from those, projectile can use SPAWN and FOLLOW (like explained above). SPAWN could be used if you want projectile to have special spawn effect. FOLLOW could be used if projectile changes animation after hitting something. You must use 'remove 0' together for this otherwise projectile would disappear before it could followup. Bear in mind that projectile is moving regardless of animation it's playing.

For shooting animation, there is 'custknife' command which changes thrown knife just for respective animation. Use it together with 'throwframe' of course.

Limitation: One big flaw of 'throwframe' command is it only allows throwing projectile once per animation.

Read more: Throwing/Shooting Knives/Projectiles | OpenBoR Modding
 
Last edited by a moderator:
Thank you so much for this tutorial, @SaintJudas, it was really useful implementing a knife for my player character. I have another weapon and I wish he could throw this one to the ground while he's jumping, like a shuriken. I have tried to use load, shuriken and throwframe/shootframe but nothing happened. Using load, knife and shootframe makes him throw it straight forward like a knife while he's jumping, not down forward like a shuriken. Is there any other way of doing this?
 
Thank you so much for this tutorial, @SaintJudas, it was really useful implementing a knife for my player character. I have another weapon and I wish he could throw this one to the ground while he's jumping, like a shuriken. I have tried to use load, shuriken and throwframe/shootframe but nothing happened. Using load, knife and shootframe makes him throw it straight forward like a knife while he's jumping, not down forward like a shuriken. Is there any other way of doing this?
I suggest replacing the "load" by the "star" command at the character header and using throwframe instead of the shootframe.

1699051716721.png

1699051621869.png

1699051654993.png

 
Hey,
I suggest replacing the "load" by the "star" command at the character header and using throwframe instead of the shootframe.

View attachment 5577

View attachment 5575

View attachment 5576


Thanks a lot. I have used the star command instead of shuriken and now the behavior fits the description in the manual:

Is it possible to spawn the projectiles in a more proper position? I tried to fiddle with throwframe, but to no avail.

My jumpattack animation:
Code:
anim jumpattack
     throwframe 0 0
     delay  20
     offset 75 120
     bbox   55 35 35 55
     sound  data/sounds/kick1.wav
     frame  Data/Entities/Players/Cobra-01/Dialogo/JumpAttack-01.png
     delay  5
     attack 0 0 0 0 0 0 0 0 0 0
     frame  Data/Entities/Players/Cobra-01/Dialogo/JumpAttack-02.png
     delay  10
     frame  Data/Entities/Players/Cobra-01/Dialogo/JumpAttack-03.png
 
Is it possible to spawn the projectiles in a more proper position? I tried to fiddle with throwframe, but to no avail.
According to the manual there's no way to adjust the X/Z position using the throwframe command, only Y. In this case I suggest managing it through the projectile's offset value, or shooting starts using scripts.

@DCurrent Adding X/Z adjustment for throwframe/shootframe commands could be a good idea for the next engine builds, for some reason only height (Y) is available. I will check it in the source.
 
According to the manual there's no way to adjust the X/Z position using the throwframe command, only Y. In this case I suggest managing it through the projectile's offset value, or shooting starts using scripts.

@DCurrent Adding X/Z adjustment for throwframe/shootframe commands could be a good idea for the next engine builds, for some reason only height (Y) is available. I will check it in the source.

Err... you know I already did that, and a whole lot more. ;)

DC
 
Err... you know I already did that, and a whole lot more. ;)

DC
Great, it's good to know :)
I didn't check native functions yet, I tested only script functions related to spawn and projectiles, like the ones you fixed during the SORX tests.
 
Great, it's good to know :)
I didn't check native functions yet, I tested only script functions related to spawn and projectiles, like the ones you fixed during the SORX tests.

Actually, I already created an entirely new system of native commands for projectiles, and they work really nice. They're even documented in the wiki, but I'm not going to call attention to them in the release announcement (and I'll be taking the existing documentation on them down), because I've since come up with a better idea. What I am working on instead, is to combine all sub-entities into one group of functions. Projectiles, flash, whatever, would all use the same command set.

It will even include an initial binding setup. Nothing complex - that belongs in script, but enough that simple one shot particle effects and motion trails could be done with native commands.

DC
 
According to the manual there's no way to adjust the X/Z position using the throwframe command, only Y. In this case I suggest managing it through the projectile's offset value, or shooting starts using scripts.

@DCurrent Adding X/Z adjustment for throwframe/shootframe commands could be a good idea for the next engine builds, for some reason only height (Y) is available. I will check it in the source.

Adjusting the offset did the trick. Thanks a lot!

By the way, do you know any script that would shoot one single star instead of three?
 
By the way, do you know any script that would shoot one single star instead of three?
You can try this one:

C:
void toss(void name, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{//Toss entity with defined conditions (DEFAULT TOSS SCRIPT FOR PROJECTILES)
    void self        = getlocalvar("self");
    int direction    = getentityproperty(self, "direction");
    int x            = getentityproperty(self, "x");
    int y            = getentityproperty(self, "y");
    int z            = getentityproperty(self, "z");
    void vShot;

    if(direction == 0){dx = -dx;}
    vShot = projectile(name, x+dx, z+dz, y+dy, direction, 0, 0, 0); //GENERATE ENTITY USING "PROJECTILE", NOT "SPAWN"
    changeentityproperty(vShot, "base", 0); //BASE CONTROL
    changeentityproperty(vShot, "parent", self); //SET TO PARENT
    tossentity(vShot, Vy, Vx, Vz); //TOSS ENTITY WITH DEFINED SPEED
    
    return vShot;
}

And use like this:
C:
anim jumpattack #FRONT JUMP STARS
    loop    1 4 8
    delay    8
    offset    155 180
    bbox    135 105 38 38
    frame    data/chars/bosses/yamato/jump01.png
    frame    data/chars/bosses/yamato/jump02.png
    frame    data/chars/bosses/yamato/jump03.png
    @cmd toss "Yamato_Star" 0 41 0 2 -0.5 0
    @cmd sound "data/sounds/sorx_attack.wav"
    frame    data/chars/bosses/yamato/jump04.png
    frame    data/chars/bosses/yamato/jump01.png
    frame    data/chars/bosses/yamato/jump02.png
    frame    data/chars/bosses/yamato/jump03.png
    frame    data/chars/bosses/yamato/jump04.png
 
Back
Top Bottom