Why do my bullets not travel straight

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

I tried making a projectile weapon but it only shoots straight at certain angles. I’ve put a link of pictures to the related code of the player and bullet scenes along with its odd movement. If you have any suggestions or need more please let me know and thank you.
()
P.S. the blue mesh you can see coming out of the hand is a cylinder mesh that goes parrallel to the raycast from the head into the -z axis.

Can’t see the screenshot

Kolandrious | 2021-07-02 15:01

Your picture is not appearing. You need to use a hosting service like https://imgur.com/ for example and then use the link provided.

If I understand correctly, your bullet shoots straight (which is what you want) only a certain angle? What is the behavior when it’s not the case then?

MrEliptik | 2021-07-02 09:46

I can see the screenshot by opening it in another tab, the link just goes to an album rather than one image.

here’s a link to the album

andersmmg | 2021-07-03 06:17

Ok so the problem might me that you’re instantiating the bullet in the same scene as a child as the hand. Thus when you move the hand, the bullet will move too. So you should probably instantiate the bullet higher in the node tree, probably in the parent of the player.

MrEliptik | 2021-07-03 09:06

yea I had already a line of code for that
func _ready():
set_as_toplevel(true)

Also even if I stay still the bullet travels at angle if I’m not perfectly on the z axis.

fat_furius | 2021-07-04 23:48

thanks :slight_smile:
I didn’t know how to do that

fat_furius | 2021-07-04 23:49

I ended up changing the way I translate the bullet. Rather than giving the rigid body an impulse, I gave it a velocity using a Vector3.

fat_furius | 2021-07-06 01:35