Have a Rigidbody3d representing a ferry boat and it has a MeshInstance3D representing an azimuth thruster propeller unit. The thruster unit rotates and when thrust is applied it usually affects the Rigidbody correctly. However after a while the direction of thrust changes from the current thruster Z direction. ± 90 Deg.
What am I doing wrong?
func _process(delta: float) → void:
if Input.is_action_pressed(“rotate_right_fwd”):
$Fwd_Thruster.rotate_y(-0.01)
if Input.is_action_pressed("rotate_left_fwd"):
$Fwd_Thruster.rotate_y(0.01)
if Input.is_action_pressed("thrust_fwd"):
apply_impulse($Fwd_Thruster.basis.z,($Fwd_Thruster.transform.origin- transform.origin)) # random 90 Deg change ?!
I can’t be completely sure about whether this is the source of your issue. But there are a few things i would suggest you try when debugging this.
You are using apply_impulse inside the “_process” method, as far as i can see. This likely results in a force that is dependent on your current framerate (_process is called every frame). Possibly you intended to use apply_force inside the “_physics_process” method
You are using 3D transform rotation methods directly on a physics object. This can sometimes lead to unpredictable behavior. Try to see if using rotational force methods like f.ex. apply_torque fixes the issue (remember to set inertia for that one to work)
Thanks again for your help. Here is a link to the simulator game. Still having some issues when the ferry makes large changes in course.
Instructions: A and D rotate aft thrusters. Arrow keys rotate fwd thrusters
W and S adjust the aft thrusters power. Up and Down arrows adjust the fwd thrusters power.
Page Up and Page Down move the view fore and aft. https://67f1e5b13dca11d26f8e77b1--lovely-crumble-2d6786.netlify.app/
Hi Again
I tried the simulator game from the link.
While it’s not completely clear what, there is definitely some weird behavior going on. I could suspect that the thruster is perhaps not rotating together with the ferry. Or perhaps the calculation of the magnitude of the thruster forces is off.
In any case your next step could be to start adding some more debug information and tools to your game.
Examples could be:
Labels showing the global rotation of each thruster, and the ship at all times
Labels showing the current linear_velocity and angular_velocity of the ship
Labels showing the calculated thruster vectors, and the magnitude of them (Godot vectors have nice little methods for easily getting the magnitude of a vector, or normalizing it)
An input key for increasing the speed of the simulation when testing (you can use Engine.time_scale to modify the simulation speed)
These tools should of course not be part of your final game (or should be locked/hidden in production)
Thanks to your debuging suggestions I discovered that the points where the thrusters were applying force to the rigid body were fixed in space due to my incorrect calculation of the offset. That was why it sort of worked close to the start position and got weird the further away the ferry moved.
Was still having some errors but the following code seems to have fixed it now:
# apply fore and aft azipod thrust
fwd_thrust_point = $AmherstIslanderII/fwd_thruster.global_transform.origin-global_transform.origin
aft_thrust_point = $AmherstIslanderII/aft_thruster.global_transform.origin-global_transform.origin
fwd_thrust_direction = -$AmherstIslanderII/fwd_thruster.global_transform.basis.z
aft_thrust_direction = -$AmherstIslanderII/aft_thruster.global_transform.basis.z #apply_force(fwd_thrust_direction * RPM_fwd,fwd_thrust_point) #apply_force(-$AmherstIslanderII/aft_thruster.basis.z * RPM_aft,aft_thrust_point)