Bullet not shooting in right direction even though rotation seems correct

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lincolnpepper

In my game the player has a shotgun that they can use to shoot things. The player shotgun will look at the mouse position, and inherits from a base shotgun, and the create_shot() function in the base shotgun will create a spray_shot that has the same rotation as the shotgun. The spray_shot object will create a bunch of bullet objects with slightly varying rotations, speeds and lifetimes that move forward. For some reason, the spray shot seems to be pointed in the wrong direction. I used prints to find that the bullets are generally tending towards the same rotation as the spray shot (they are slightly varying on purpose). Here are pictures of each of the scripts involved: Imgur: The magic of the Internet
example of problem: Imgur: The magic of the Internet (sorry for weird cropping, obs was being weird)
it’s weird that there is a problem, because the shotgun also sends a signal to the player to recoil from the shot and that works fine. This has been a problem for a while, so any and all help is greatly appreciated.

:bust_in_silhouette: Reply From: Joel_127
shot_instance.rotation = rotation
$Shots.add_child(shot_instance)

what you are doing here is setting the rotation of the pellets to the same rotation of the shotgun. The issue here is “rotation” is the local rotation of the object, not the global one.

For example if your shotgun have a 45° rotation, your pellets will have a 90° rotation (45 + 45), because their rotation is relative to the parent. What you need to do is set the rotation to 0 (I assume the node $Shots is a child at the end of the shotgun and pointed at the right direction).

Same with position (setting a local position to a global position makes no sense).

I hope this helps :slight_smile:

the $Shots node is a blank node so that shots put under it will not inherit any position or rotation from the parent.

However, i added the bullets directly under the spray shot object, so they inherited the rotation from the spray shot. Thank you!

lincolnpepper | 2019-04-09 15:33