Need help rotating a holdable object

(Godot Version 4.2.2)

Problem

I’ve been trying to create a pick-up system for my character which is able to interact with godots physics (similar to Half-Life 2).

The code gets the direction between the current position and the goal position, then sets the velocity to direction * 10 * distance (I multiply by distance to avoid overshooting; 10 is just an arbitrary number). I do this for both rotation and position

var hold_pos = pitch.global_position + -pitch.global_basis.z * 2
		
var move_dir = item_held.global_position.direction_to(hold_pos)
var rot_dir = item_held.global_rotation.direction_to(pitch.global_rotation).normalized()
		
var move_dist = clamp(item_held.global_position.distance_to(hold_pos),0,5)
var rot_dist = clamp(item_held.global_rotation.distance_to(pitch.global_rotation),-1,1)
		
item_held.linear_velocity = move_dir * 10 * move_dist
item_held.angular_velocity = rot_dir * 10 * rot_dist

The problem is with rotation. It seems that when facing a certain angle the object just can’t rotate correctly (?).

Heres a video showcasing the problem:

I found a solution!

Turns out there’s a node which can help with that. While it gives results a bit different they might be even better.

I used a Generic6DOFJoint3D node (amazing name by the way). I set its node_a to a static body that is parented to the camera, and its node_b to the object that is being held.

Simple as that:
pickup_joint.set_node_b(item_held.get_path())

Hope I explained the solution well enough for others in need of it to understand

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.