|
|
|
|
Reply From: |
godot_dev_ |
How I solved this is defined two type of projectiles:
- Stage projectiles
- Player projectiles
Stage projectiles are the standard projectile like a street fighter haduken. They spawn on the stage, and they are relatively independent from the player who spawned it. The only link it has to the player is when it initially spawns, the position is relative to the player but the projectile is added as a child to the node representing the stage. That way, if the player (also a child of the stage) moves, the projectile isn’t affected
Player projectiles are specials projectiles that will stick to the player. This is achieved by making the projectile a child of the player’s node. In this case, if the player moves, the projectiles also moves with the player. An example of this type of projectile is the leaf attack of mega man from Super Smash Bros 4, where the leaves spin around mega man and act as a shield (he can then throw the leaves, which become Stage projectiles, since they lose their positional link to the player.
What both types of projectiles should have in common is a) they have an initial spawn point that is likely relative to the player/creature spawning it; and b) is from their point view, it doesn’t matter who their parent is; they can have their own movement animation without having to worry about the parent’s movement.
For example, if the SSB4 mega man leaf projectile example above were a stage projectile, since the projectile doesn’t move at all in relation to megaman, when on the stage the leaves would simply be stationary and not move, even if megaman moves. In the example of the SF haduken, if it were a player projectile, if Ken/Ryu shoot this type of haduken, when they remain stationary, the haduken will appear to travel normally across the stage, but if ken/ryu back up, the projectile will also backup at the same speed even if it’s traveling forward (and it will relatively speed up if the player walks forward) since it’s anchored/linked to the player.
Therefore, you can have 1 type of projectile scene, and the only thing that changes is whether it is a child node of the player or stage, and that’s how you can have many types of projectiles that are sticking to the player or independent to the stage.
Thanks! That’s a fantastic and in depth answer. I honestly never really considered categorizing them into Stage and Player projectiles.
karltha | 2022-09-02 05:12