Solved How to make Entity to return upon hit

Question that is answered or resolved.

SEEGET

Member
Hi guys, I've been working on this shield throwing for cap however because it goes through the enemy and takes time to come back while playing the full animation leaving cap open for attacks by the enemy. How can I make it so the shield returns upon impact? Your advice is always greatly appreciated.
Regards
 

Attachments

  • Screenshot 2025-08-09 193006.png
    Screenshot 2025-08-09 193006.png
    38.6 KB · Views: 9
  • lv_0_20250809194203.gif
    lv_0_20250809194203.gif
    802.5 KB · Views: 11
  • lv_0_20250809193957.gif
    lv_0_20250809193957.gif
    676.7 KB · Views: 11
  • Screenshot 2025-08-09 193006.png
    Screenshot 2025-08-09 193006.png
    38.6 KB · Views: 7
Are you saying that you want that shield to be separate from its parent/source (Captain America) every time it swiftly moves like a boomerang and returns to its owner?
 
There are more than one types of boomerang in video games, just to name a few:
1. Basic : flies than flies to opposite direction whether it hits anything or not. Ex: Holy cross in Castlevania games.
2. Parented : flies than returns to thrower or parent whether it hits anything or not.
3. Like #1 but dies on contact with anything.
4. Chases enemies than returns to thrower after it's done chasing. Ex: Cap America's shield.

If you need example of #4, you can find it in Avengers Template.

About your version of the shield, I need to ask this: what happens if the shield doesn't hit anything before it flies back to Cap?
 
There are more than one types of boomerang in video games, just to name a few:
1. Basic : flies than flies to opposite direction whether it hits anything or not. Ex: Holy cross in Castlevania games.
2. Parented : flies than returns to thrower or parent whether it hits anything or not.
3. Like #1 but dies on contact with anything.
4. Chases enemies than returns to thrower after it's done chasing. Ex: Cap America's shield.

If you need example of #4, you can find it in Avengers Template.

About your version of the shield, I need to ask this: what happens if the shield doesn't hit anything before it flies back to Cap?
I'd love to do 3 and 4. The shield does return even when it doesn't hit the enemy. Just some clever mapping and timing I'll share the txt file I used for the shield I created
 
name shieldslice
health 10
type none
hostile enemy obstacle
subtype chase
gfxshadow 1
lifespan 9
subject_to_gravity 0
candamage enemy obstacle



animationscript data/scripts/grabscript.c
















anim idle
loop 0
delay 1
@script
if(frame != 0){
int martelo = getglobalvar("shieldslice");
if(martelo == 0){
void self = getlocalvar("self");
killentity(self);
}
}
@end_script
hitfx data/sounds/klunk2.wav
@cmd velo001 9 0 0
attack 18 8 32 16 30 5 0 0 0 0
dropv 4 2
sound data/sounds/vuu3.wav
@cmd spawn01 "ShieldTrail" -1 0 0
offset 35 22
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo.gif
@cmd spawn01 "ShieldTrail" -1 0 0
delay 2
@cmd velo001 4 0 0
frame data/chars/capamerica/escudo2.gif
@cmd spawn01 "ShieldTrail" -1 0 0
@cmd velo001 3 0 0
frame data/chars/capamerica/escudo2.gif
@cmd velo001 2 0 0
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo2.gif
@cmd velo001 1 0 0
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo2.gif
@cmd velo001 0 0 0
@cmd spawn01 "ShieldTrail" -1 0 0
frame data/chars/capamerica/escudo2.gif
@cmd velo001 -3 0 0
delay 7
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif
frame data/chars/capamerica/escudo.gif


#|edited by openBor Stats v 0.67
There are more than one types of boomerang in video games, just to name a few:
1. Basic : flies than flies to opposite direction whether it hits anything or not. Ex: Holy cross in Castlevania games.
2. Parented : flies than returns to thrower or parent whether it hits anything or not.
3. Like #1 but dies on contact with anything.
4. Chases enemies than returns to thrower after it's done chasing. Ex: Cap America's shield.

If you need example of #4, you can find it in Avengers Template.

About your version of the shield, I need to ask this: what happens if the shield doesn't hit anything before it flies back to Cap?
i have downloaded your resource thanks ill go through it asap and learn.
 
Code:
name    shieldslice
health    10
type    none
hostile enemy obstacle
subtype chase
gfxshadow 1
lifespan 9
subject_to_gravity 0
candamage enemy obstacle



animationscript data/scripts/grabscript.c
















anim    idle
    loop    0
    delay    1
    @script
           if(frame != 0){
         int martelo = getglobalvar("shieldslice");
         if(martelo == 0){
        void self = getlocalvar("self");
     killentity(self);
        }
        }
    @end_script
    hitfx    data/sounds/klunk2.wav
    @cmd    velo001    9 0 0
    attack    18 8 32 16 30 5 0 0 0 0
    dropv    4 2
    sound    data/sounds/vuu3.wav
    @cmd    spawn01 "ShieldTrail" -1 0 0
    offset    35 22
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    delay    2
    @cmd    velo001    4 0 0
    frame    data/chars/capamerica/escudo2.gif
    @cmd    spawn01 "ShieldTrail" -1 0 0
    @cmd    velo001    3 0 0
    frame    data/chars/capamerica/escudo2.gif
    @cmd    velo001    2 0 0
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo2.gif
    @cmd    velo001    1 0 0
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo2.gif
    @cmd    velo001    0 0 0
    @cmd    spawn01 "ShieldTrail" -1 0 0
    frame    data/chars/capamerica/escudo2.gif
    @cmd    velo001    -3 0 0
    delay    7
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif
    frame    data/chars/capamerica/escudo.gif

        
#|edited by openBor Stats v 0.67
 
The code plus how I executed the shield to go and come in the character file giving that result below in the gifs.
 

Attachments

  • Screenshot 2025-08-09 193006.png
    Screenshot 2025-08-09 193006.png
    38.6 KB · Views: 9
  • lv_0_20250809193957.gif
    lv_0_20250809193957.gif
    676.7 KB · Views: 9
  • lv_0_20250809194203.gif
    lv_0_20250809194203.gif
    802.5 KB · Views: 9
i did put subtype chase but it doesnt work it just goes and comes back

Entities with subtype chase need to be on ground so they can walk and chase. Even so they won't return to whoever throw/spawn them on contact.

I forgot to ask more about your shield:
1. Do you want it chase enemy or not? if yes, the shield could fly back to chase enemy behind Cap.
2. When it returns to Cap, is it limited by z axis i.e only moves in one z axis or not? the former is how boomerang works in Return of Double Dragon IIRC. The former also means if Cap moves to different z axis the shield won't return to him.
 
Entities with subtype chase need to be on ground so they can walk and chase. Even so they won't return to whoever throw/spawn them on contact.

I forgot to ask more about your shield:
1. Do you want it chase enemy or not? if yes, the shield could fly back to chase enemy behind Cap.
2. When it returns to Cap, is it limited by z axis i.e only moves in one z axis or not? the former is how boomerang works in Return of Double Dragon IIRC. The former also means if Cap moves to different z axis the shield won't return to him.
Hi, thanks for responding and clarifying on chase.
To answer your first no I don't really want it to chase the enemy. What I really wanted was once the shield hit the enemy it immediately returns without having to play out the full animation. With the way I did mine I don't think it's possible. But if there is a workound to when thrown in a straight direction it returns immediately upon hitting an enemy or impact with an object.
after looking at the resource for avengers template it was quite interesting and would love to get into it and try some experiments. Thanks.
 
I have a rather rough design of the boomerang below. I'm using files I have so you'd need to replace them with yours.
Code:
name            BStar2
speed           20
type            none
gfxshadow       1
remove        0
subject_to_gravity 0
candamage    enemy obstacle
offscreenkill    1000
lifespan        10
palette        data/chars/misc/shot/bstarG.png


anim    idle
    loop     1
    delay     6
    followanim 1
    followcond 1
    offset     14 14
    attack     1 3 25 19 10
        hitfx    data/sounds/slash.wav 
        hitflash slash2
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    attack     0
    frame     data/chars/misc/shot/bstar3.gif
    attack     1 3 25 19 10
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    attack     0
    frame     data/chars/misc/shot/bstar3.gif

anim    follow1
@script
  if(frame == 1){
    void self = getlocalvar("self");

    changeentityproperty(self, "speed", 0);
  }
  if(frame >= 2){
    void self = getlocalvar("self");
    void Own = getentityproperty(self, "owner");
    
    if(Own){
      int x = getentityproperty(self, "x");
      int z = getentityproperty(self, "z");
      int Ox = getentityproperty(Own,"x");
      int Oz = getentityproperty(Own,"z");
      int dx, dz;

      if(Ox > x){
        dx = 6;
      } else {
        dx = -6;
      }

      if(Oz > z){
        dz = 3;
      } else {
        dz = -3;
      }

      changeentityproperty(self, "position", x+dx, z+dz);

      if(x < Ox+15 && x > Ox-15){
        killentity(self);
      }
    }
  }
@end_script
    loop     1 2 8
    delay     1
    offset     14 14
        hitfx    data/sounds/slash.wav 
        hitflash slash2
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    delay     3
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar3.gif
    frame     data/chars/misc/shot/bstar3.gif #
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar3.gif
    frame     data/chars/misc/shot/bstar3.gif

This Bstar2 will fly forward when thrown using projectile function. If it hits nothing, it won't return but if it hits something, it will return to the thrower.
I could update it for smoother movement but this will do for now.
 
I have a rather rough design of the boomerang below. I'm using files I have so you'd need to replace them with yours.
Code:
name            BStar2
speed           20
type            none
gfxshadow       1
remove        0
subject_to_gravity 0
candamage    enemy obstacle
offscreenkill    1000
lifespan        10
palette        data/chars/misc/shot/bstarG.png


anim    idle
    loop     1
    delay     6
    followanim 1
    followcond 1
    offset     14 14
    attack     1 3 25 19 10
        hitfx    data/sounds/slash.wav
        hitflash slash2
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    attack     0
    frame     data/chars/misc/shot/bstar3.gif
    attack     1 3 25 19 10
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    attack     0
    frame     data/chars/misc/shot/bstar3.gif

anim    follow1
@script
  if(frame == 1){
    void self = getlocalvar("self");

    changeentityproperty(self, "speed", 0);
  }
  if(frame >= 2){
    void self = getlocalvar("self");
    void Own = getentityproperty(self, "owner");
   
    if(Own){
      int x = getentityproperty(self, "x");
      int z = getentityproperty(self, "z");
      int Ox = getentityproperty(Own,"x");
      int Oz = getentityproperty(Own,"z");
      int dx, dz;

      if(Ox > x){
        dx = 6;
      } else {
        dx = -6;
      }

      if(Oz > z){
        dz = 3;
      } else {
        dz = -3;
      }

      changeentityproperty(self, "position", x+dx, z+dz);

      if(x < Ox+15 && x > Ox-15){
        killentity(self);
      }
    }
  }
@end_script
    loop     1 2 8
    delay     1
    offset     14 14
        hitfx    data/sounds/slash.wav
        hitflash slash2
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    delay     3
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar3.gif
    frame     data/chars/misc/shot/bstar3.gif #
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar1.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar2.gif
    frame     data/chars/misc/shot/bstar3.gif
    frame     data/chars/misc/shot/bstar3.gif

This Bstar2 will fly forward when thrown using projectile function. If it hits nothing, it won't return but if it hits something, it will return to the thrower.
I could update it for smoother movement but this will do for now.
Thanks bro you're awesome 🙏🙏🙏🙏
 
Back
Top Bottom