Basically, I have a simple pick up system in which a rigidbody is given forces to move toward’s a certain point in front of the camera, but I also wanted to add a way to rotate the object to inspect it, but I can’t figure out how to make it relative to the camera’s rotation. I basically want to achieve something like a skewer.
The image above explains how I imagine the system to work, where mouse motion from left to right rotate the object on the y camera axis and up and down rotate the object on the x camera axis.
When you pick up an object, reparent it (temporarily) to a special pivot node. This node can be a child of the camera (or just always looking at the camera or something like that). And then when you want to inspect the object, you rotate the pivot, which is aligned with the camera at all times. And that rotates the object too.
And when you drop the object, reparent it back to the world and reset the pivot rotation.
You could also play a trick by moving the Rigidbody to the inspection position, hiding it from the camera, then using another camera to view a Meshistance of the exact same object to inspect and rotate it. When you’re done, swap back.
Ah, figured it out by accident.
I managed to make it work using global_rotate and using the camera basis axis for the axis variable. (for the record this script is attached to the camera)
var prev_mouse_pos: Vector2
func _process(delta):
var new_mouse_pos = get_viewport().get_mouse_position()
var pos = new_mouse_pos - prev_mouse_pos
var angle = pos * 0.01
currentGrab.global_rotate(global_transform.basis.x,angle.y)
currentGrab.global_rotate(global_transform.basis.y,angle.x)
prev_mouse_pos = new_mouse_pos