Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ReeceRackley · Jun 06, 2018 at 02:46 PM · vrobjectsoculusoculusriftobjects-movement

Picking up object, then locking it back into same position "Oculus VR"

Hi,

I'm using OVR Grabbable component to pick up a "Cube" for example, moving it around in front of the Oculus headset. I would like to be able to put the "Cube" back in the location I picked it up from, almost as if the object locks back into place / magnetic.

Could anyone help me with a script or explain how to do it, I'm really struggling.

Any help would be greatly appreciated.

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harinezumi · Jun 06, 2018 at 03:00 PM 0
Share

Store the desired position and rotation of the object (for example in a SavePosition() function), and let it have a bool isHeld variable which you set to true when holding the item, and false when not. Finally, in Update() if isHeld is false lerp back the position and rotation to the one you saved the in SavePosition().

avatar image ReeceRackley Harinezumi · Jun 06, 2018 at 03:10 PM 0
Share

Hi, Is that using a C## script? if so could you please help me? I'm unsure on how to write it.

Thanks,

avatar image Harinezumi ReeceRackley · Jun 06, 2018 at 03:19 PM 0
Share

As UnityScript support is being ended, and Boo hasn't been supported for a long while now, yes, it is C#.

Try the below outline of a script. Call SaveReturnPoint() and SetIsHeld(true) when you take the object, and just SetIsHeld(false) when you let go of it.

 public class ReturningObject : $$anonymous$$onoBehaviour {
 
     private Vector3 returnPosition;
     private Quaternion returnRotation;
 
     private bool isHeld = false;
     public void SetIsHeld (bool value) { isHeld = value; }
 
     public void SaveReturnPoint () {
         returnPosition = transform.position;
         returnRotation = transform.rotation;
     }
 
     private void Update () {
         if (!isHeld) {
                 transform.position = Vector3.Lerp(transform.position, returnPosition, 0.5f);
                 transform.rotation = Quaternion.Lerp(transform.rotation, returnRotation, 0.5f);
         }
     }
 
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RedMoonGms · Jul 02, 2018 at 03:23 PM

Maybe you could use Input.GetKeyUp and make an animation of the object getting back to position.

void Update() { if (Input.GetKeyUp("Action")) TheObject.GetComponent<Animation> ().Play ("ObjectBackToPlace");

This way the object should get back as you stop pressing a certain key. I'm not very well at scripting so, I'm not sure this could work. Hope this helps anyway.

BTW, this script should be activated only when you are holding the object.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to disable automatic recentering when using OVRCameraRig 0 Answers

Pulling Object forwards and back "Oculus VR" 0 Answers

Disabling VR Camera rotation creates ''cinema'' effect in VR device 1 Answer

How do you detect the Oculus remote without using OVRInput? 0 Answers

PlayOneShot in footstep script does not always play when called (<10% of the time) and rarely, if ever timed properly 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges