godot-xr-tools
godot-xr-tools copied to clipboard
Feature Request - Allow dynamic movement of object pickables in hand while picked up
Right now, a dev can set the PickupCenter node to properly place an object for a hand but some objects are asymetrical and therefore need different PickupCenter positioning to look good in either hand. My current example is a phone that only has one side with buttons and is typically held sideways. When held with the left hand it has to face right, and when held with the right it has to face left. I implemented the following code and the change works but only once the item is dropped and picked up again. Moving the code to the process function does not change the result. It would be good to develop a functionality to allow the object to change position depending on which hand picks it up (maybe two PickupCenter nodes?) or even more flexibly just to be changed at any time dynamically with code.
#Rotate phone into correct hand position for left or right hand
func _on_PickablePhone_picked_up(pickable):
if by_controller != null:
if by_controller.get_node_or_null("LeftPhysicsHand") != null:
$PickupCenter.rotation_degrees.y = 90
$PickupCenter.translation.z = .00
else:
$PickupCenter.rotation_degrees.y = -90
$PickupCenter.translation.z = .1
In the meantime, for anyone else that has this issue, I found a workaround that should work in a lot of cases at least for direct grabbing (won't work for remote grabbing). Place an area relatively close to the object to be picked up but greater than the usual grab range you have your function_pickup set to. Set its collision layer to the same layer as the XR Tools physics hands are set (mine are layer 18) so they pick up the physics hands bone collisions, and connect the on body entered signal of that area to your pickable object or handler node with code like this (of course with your specific necessary adjustments to your particular pickup center nodes):
func _on_CenterNodeChangeArea_body_entered(body):
if body.is_in_group("left_hand"):
$PickupCenter.rotation_degrees.y = 90
$PickupCenter.translation.z = .00
if body.is_in_group("right_hand"):
$PickupCenter.rotation_degrees.y = -90
$PickupCenter.translation.z = .1
time to chime in, as i was the one who brought this up on discord its time to explain what i wanted this for and how i more or less solved it
in my case am using a handheld that resembles the looks of a gameboy/gamegear console and therefore the way it should be grabbed is either on the left corner or the right corner depending on the hand that grabs it
at the beginning i tried to translate the PickupCenter but it just doesnt work quiet the way one would expect or think, therefore instead of going towards the mountain am moving the mountain... With that being said am changing the translate/rotation of the Meshinstance itself
func _on_GearBoy_picked_up(pickable):
if by_controller != null:
if by_controller.get_node_or_null("LeftPhysicsHand") != null:
$GearBoy.rotation_degrees.x = 0
$GearBoy.translation.x = 0.115
$GearBoy.translation.z = 0.015
$GearBoy/CartidgeSlot.visible = true
else:
$GearBoy.rotation_degrees.x = 30
$GearBoy.translation.x = -0.12
$GearBoy.translation.z = 0.02
$GearBoy/CartridgeSlot.visible = true
func _on_GearBoy_dropped(pickable):
$GearBoy/CartridgeSlot.visible = false
On a Sidenote it is a bit odd, when you look at the code, especialy the translation.z/x parts, they arent centered. Why, well if i keep the distance the same, the right one is off, too close to the pickupcenter. Now this might just be my model but if i encounter this again in the future,... it might end up as a issue ticket.
Since the above doesnt work well with collisionshapes, one needs to adjust the collisionshape together with the model and that ends in spaghetti code...
So i just found out that by modifying left/right function_pickup - editing the transform of the function_pickup on left and right = Potential way to have the pickedup pickable have proper Positioning when it comes to items such as handhelds
this should be closed since the multiple grabpoints pr added the above funcionality