How to convert Node3D's rotation to a vector

Godot Version

4.6.1-stable

Quesion

I feel like I’m having a problem that’s caused by doing things the wrong way. I have a weapon bound to the player camera which spawns a bullet, and sets its transform to the one of a ShootOrigin Marker3D. This works correctly however I don’t know how to make it move in its relative Z+ (as it’s marked top level to avoid it being rotated by the player rotating the view).

The solution I came up with was to create a new Vector3 and calculate the absolute change in position for each axis using sin and cos however I’m ashamed to admit I did not pay enough attention in physics class.

Should I see if I can study up on how to do calculations on vectors in 3D space or did I miss something?

Move it along marker’s global_basis.z value at the moment of spawning.

1 Like

I cant say that definitely ; but i think this can help you :

first create a basic node or marker3d as the child of your gun or anything you want to rotate and put it before the rotating object ( gun or anything ) ;

than you can make a vector from the rotation by ( marker.global_position - gun.global_position).normalized()

That wouldn’t work, the marker is fixed to the gun, which is fixed to the player and their camera, so if bullet moves along the marker’s global_basis and the player moves wouldn’t the bullet move with the player?

It’d work if you copy that vector’s value at the moment you spawn the bullet and continue using it onward.

No it just makes a direction and it wouldnt move the bullet with player