Limiting rotation of an XRToolsPickable

Godot Version

4.3

Question

In the AR game I’m developing I have several XRToolsPickables . Some of these I’d like to be able to move in all directions, but only allow to rotate around the Y axis. I specifically don’t want them to rotate around the X and Z axis (along the lines of the game platform in Angry Birds VR) . I’ve been mostly successful by overriding _physics_process on my pickable subclasses

func _physics_process(delta):
	if is_picked_up():
		rotation.x = 0
		rotation.z = 0
		force_update_transform()

What I see though is the grab point is visually off from where the user grabbed the object

I’ll start investigating the use of actual XRToolGrabPoint objects (and perhaps intractable and handles as well) but I’m curious if others know a better / easier way of accomplishing what I’m trying to accomplish

Update: I tried setting XRToolsGrabPoints but unfortunately they don’t seem to work well in combination with the degrees of freedom limiting code I added to my pickable node.

As the pickupables system invariably links the positioning and rotation of the held object to that of the hand, there is indeed no support here for further contraints (other than the two handed implementation).

Have a look at the interactables demo in the main XR tools demo that shows off the interactable types. These are positional and/or rotationally locked objects that can be manipulated with hands. Here the hands location is fixed to the object and the object drives the positioning.

1 Like

Thanks!

After digging into how the transform for the held object was calculated I had one other thought that seems to be working out well - instead of adjusting the transform of the picked up object, I constrained the allowed rotations of the picker by extending FunctionPickup

class_name AlwaysUpPickup extends XRToolsFunctionPickup


func _process(delta: float) -> void:
	global_rotation.x = 0
	global_rotation.z = 0
	super(delta)

Now I can

  • Precisely grab my pickable objects at any point and have the grab point remain fixed
  • Move them / rotate them around the Y axis without worrying about rotations around the other axis which would be invalid in my game

I figure something like this may be generally useful for games where players are laying down train tracks or placing lego pieces or the like

1 Like

Indeed, all sorts of logic where you want to snap the thing you’re holding to where it will end up when let go, would benefit from rethinking our strategy here.

Right now we drive everything through the hands, and we jump through hoops when the held object is constraint in some way, whether because it interacts with other physics objects, whether we’re doing two handed pickups, or in a situation as yours where you want to limit movement.

I hope to find more time to experiment with it but I’m starting to think along lines that once you pick an object up, positioning is no longer driven by hand positions, but the tracked location of the hand or hands drive the movement of the object, and the hands are simply drawn where they end up even if detached from their actual tracking location.

Still working through what that would look like :slight_smile: