Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

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

VJ76VJ76 Posts: 49
Brain Burst
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


  • FocusVRGamesFocusVRGames Posts: 95 Oculus Start Member

    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

Sign In or Register to comment.