Forum Discussion
VJ76
7 years agoProtege
[Delete] Returning a gameobject to original position when release a grab from touch controller.
I'm having a scene with multiple gameobjects that i can grab. I am using the OVR Grabber and Grabbable scripts, but I want to set it up so that when the player releases the object in a certain distance, it snaps back to it's original position and rotation. Without using vrtk
1 Reply
- FocusVRGamesAdventurerHi
I have done something similar but without the distance check so will summarise what I did below
Write a new script and attach it to the object you want to return to a location
In the script create some variables
a reference to your Grabbable script.
variables to store the transform and rotation.
a bool for tracking if the object has been picked up
In the update command add a if statement to track when the object is grabbed and set the position variables the the current location
If grababble.grabbed and not pickedup then
pickedup = true
rotation = current rotation
position = current position
add another if statement in the update to track when the object is released
If not grababble.grabbed and pickedup
pickedup = false
reset the position and rotation of your object
(Note you may want to use iTween or something similar here so it snaps back gracefully.
Within distance check
if you want to perform the snap only within a certain distance you will have to calculate on release if it is within that distance, which off the top of my head I believe you can use magnitude or vector3.distance
Hope that helps
Mike
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago