0 votes

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 createshot() function in the base shotgun will create a sprayshot 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: https://imgur.com/a/B5NFN5X
example of problem: https://imgur.com/a/VsPGaK9 (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.

in Engine by (243 points)

1 Answer

+1 vote
Best answer
shot_instance.rotation = rotation

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 :)

by (283 points)
selected by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.