(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: