Godot Version
4.2.2
Question
Hi. Im still really new to godot game development so i still have a lot of questions. i’ve currently started developing a roguelike, where the player can shoot bullets. for some reason, whenever i create the instance of the bullet, it is way off from the position i told it to spawn at:
I dont really understand why this happens, because im sure i’ve done everything correctly. here are the screenshots just in case:
Player Shooting Code:
Projectile code:
(Speed is set to 5 for testing purposes, that was how i found the bug)
help would be appreciated.
P.S - how would i make it so that the bullet gets shot towards the cursor?
-
Sure why not, this issue happened because first you added the bullet in player position as a child get it’s parent position, so example the player position is Vector2(10, 10) so after adding the bullet, you applied it’s position to shooting point global position means Vector2(10, 10), I let the shooting point position 0 so 10+10 = 20 means your bullet spawn in Vector2(20, 20) not Vector2(10, 10) and also it is odd to spawn the bullet inside player, so the bullet will moves with the player because as I mentioned a child always follows it’s parent position
-
After adding the bullet in scene tree, means after add_child, add this code:
bullet.look_at(get_global_mouse_position())
Thanks for the explanation and help. appreciate it
1 Like