cancel
Showing results for 
Search instead for 
Did you mean: 

[Delete] Returning a gameobject to original position when release a grab from touch controller.

VJ76
Level 4
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 1

FocusVRGames
Level 5
Hi

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