#Spaceship thrusters system

1 messages · Page 1 of 1 (latest)

honest storm
#
func apply_thrust(linear_input, angular_input):
    var force = magnitude * global_basis.y
    var lever_arm = position - get_parent().center_of_mass
    var torque = lever_arm.cross(force)
    
    var global_linear_input = global_basis * linear_input
    var global_angular_input = global_basis * angular_input
    
    var dot_linear = force.normalized().dot(global_linear_input)
    var dot_angular = torque.normalized().dot(global_angular_input)
    
    if dot_linear + dot_angular > EPS:
        material.set_shader_parameter("fade", 1.0 /  min(dot_linear + dot_angular, 1.0))
        get_parent().apply_force(force * min(dot_linear + dot_angular, 1.0), global_position - get_parent().global_position)
    else:
        material.set_shader_parameter("fade", 100.0)
#

i have a rigidbody that contains multiple Node3D that represents thrusters. every frame i call this function on each thruster, linear_input and angular_input are both vector3 for x, y, z and pitch, yaw, roll, all of them between -1 and 1

#

basically, if a thruster y axis is aligned with the linear_input, or if it will produce torque matching angular_input, the thruster apply its force to its parent

#

but the result doesn't work at all for the rotation ! where is my mistake ?

honest storm
#

Well i remade everything wth global coordonates instead, and it worked