How can I add an inspect rotation to my grab system?

Godot Version



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.

This is a bit dated, but it might give you an idea of how you can approach the problem: How do you rotate a Spatial node around an axis at a given point in space? - #2 by system

I’d probably do this with a pivot node.

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.

This doesn’t work because the object is a Rigidbody so it would break the physics since the camera is updated in _process

Maybe that video can help

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
   prev_mouse_pos = new_mouse_pos

Nice work! Thanks for posting your solution. I’m sure someone else will stumble across this in the future.