As the player moves, the projectiles move along the player instead of simply travelling by themselves.
The player jumping showcases this (And with collisions visible, you can get a clearer idea as the projectile is still attached to its source).
But when the player moves horizontally, you can see it affect the projectile even if it’s a bit subtle.
Another incident that happens is, when the projectile travels and the player moves vertically, if there’s a floor or ceiling, the floor/ceiling “push” the projectile up or down depending on how it touches those surfaces.
This weird issue also happens with an enemy type in the game, known as the “Hirdrih Servant” (hirdrih_servant).
I also plan in the future to add more enemies and some bosses that spawn projectiles, so I hope a solution is something that can also apply to them as well.
Here are the scenes and scripts I think are relevant (Since I’ll continue to put my games on GitHub so people can see what’s in them):
Regardless any help is appreciated.
(Also I have a bunch of other issues with the game and they’re named on the GitHub page, but I think I should try and focus on one by one).
I didn’t dig through all your code, but I can tell you what your problem is. when you create the projectile you are doing something in your SourceEntity like this:
var projectile = PROJECTILE.instantiate()
add_child(projectile)
This is making the projectile a child Node of your SourceEntity - which means its location is relative to its parent. So when the parent moves, the projectile’s relative location is updated and it gets dragged along.
Try this:
var projectile = PROJECTILE.instantiate()
get_parent().add_child(projectile)
Should add it to the level itself and solve the problem.
I imagine that when you instantiate your projectile, you add it as a child of the player? Then the projectile will inherit the player’s movement. The fix is to add it as a child to a node that doesn’t move. You can use, for example, get_tree().root, or some other container you specifically create for this. I would fix this first, and then tackle the floor ceiling. What should happen when a projectile touches the floor or ceiling?
dragonforge-dev is very likely correct, I’d just like to add that rather than adding it to the parent of the spawner, it would be wise to have some “spawn manager” that the entity spawning the projectile can call up to. This spawn manager will ensure the projectile is created in the correct space, that typically houses all of your entities, so that any changes that may occur on other nodes in the hierarchy won’t impact your projectile.
EDIT: Looks like MrWetsnow mostly beat me to this.
From a programming perspective, anything with the name Manager is a bad idea. It’s called the Manager Anti-Pattern. I discuss it at great length here, as well as how to avoid it (and why): Architectural Problems - #10 by dragonforge-dev Here’s a couple more discussions on here about it:
@OnionKing makes a solid point that if you don’t know what the projectile creator’s parent is, you should be careful. But likely it’s either the Level itself or a Node2D/3D used for organizing nodes. Either way, it’s typically a safe bet. If you need more control on where the projectile spawns, have the object that spawns it be responsible for figuring that out.
I won’t dispute the usage of the term manager, if only because it’s overly broad, but a “Spawner” node is a good way to help keep your tree flexible, in my experience. It creates an easy target for arbitrary nodes to call up to in order to ensure all entities being spawned are placed into a shared “space” where all their coordinates will align. You could also pair this with your higher level “Level” or “World” logic, or implement it any hundreds of other ways, but I don’t think what I’m suggesting itself falls into the manager anti-pattern.