Godot Version
4.7.2
Question
I am making a simple grabbing system, using physics functions (applying impulse/force), and it’s going quite well, but I don’t know how to keep the grabbed object with its global.basis.y (or, even better, a custom up vector, since i’m gonna also implement a rotation around its origin) facing upwards (by applying torque).
Here is the code i’m using
#in the player script
held_object.grab_point = raycast.global_position + ( - raycast.global_basis.z ) * holding_distance
held_object.ray_dir = - raycast.global_basis.z
#in the object script
if global_position.distance_to( grab_point ) < 5.0:
linear_velocity = Vector3.ZERO
apply_central_impulse( ( grab_point - global_position ) * follow_grab_strength )
elif global_position.distance_to( grab_point ) >= 5.0:
self.gravity_scale = base_gravity_scale
picked = false
if global_rotation.distance_to( ray_dir ) > deg_to_rad(10):
angular_velocity = Vector3.ZERO
apply_torque_impulse( ray_dir.cross(- global_basis.z ) )
I currently cannot post a video since I’m a new user, but will post it in the comments if I can.