So I want to throw a ball to a certain direction using apply_central_impulse()
In my scene I have set a MeshInstance3D, a straight line, as a reference to the angle I want my ball (a RigidBody3D) to go.
When I apply an impulse of Vector3(0, 0, -1) (if i understand this correctly X is basically the direction, Y is how much I want it to go in the air, and Z is how far I want it to go) it goes in a straight line, as expected.
Now what I would like is to set the X impulse based on the rotation of my reference straight line.
For instance when I apply a Vector3(1, 0, -1) impulse it goes to a direction of -21deg / approximately -0.35rads, But when I apply an impulse of Vector3(pointer_rotation.y, 0, -1) (pointer_rotation.y being the rotation of my reference straight line in radians) it doesn’t work.
Maybe I should use something else than apply_central_impulse ? I don’t know.
If i understand correctly, your reference line is pointing in the direction and angle you would like your ball to travel?
Apply Central impulse I believe is taking a vector for the direction of the impulse to apply, so it’s less about angle.
Essentiall what you could do is take the direction of your line and just pass that as your vector. (assuming the line moves in the direction of its forward axis z) Otherwise, if you know your line’s start and end points, you could Subtract point A from point B and pass the result vector.
I might give it a try, but in the meantime, with a bit of help from AI, I think I achieved something.
Here is some of my code as it might be useful I guess :
var impulse_magnitude = 5 (arbitrary value)
var impulse_x = sin(pointer.rotation.y)
var impulse_z = cos(pointer.rotation.y) # Use rotation.y for both x and z
var impulse = Vector3(impulse_x, 0, impulse_z) * impulse_magnitude
ball_instance.apply_central_impulse(impulse)