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 keith_ttlabs · Jan 04, 2017 at 11:08 AM · vrquaternionmath

NewtonVR fix. Translating a point and rotation inline with changes from another gameobject.

Hi, I make NewtonVR, a free, opensource, physics based, interaction framework for vr. The meat of NewtonVR is being able to hold a vr controller over a virtual object, hold a button, and "pick up" that item. The way we currently do this is by creating a transform (PickupTransform) at the point the item is at, then setting the parent of that transform to the controller (NVRHand).
See here: https://github.com/TomorrowTodayLabs/NewtonVR/blob/master/Assets/NewtonVR/NVRInteractableItem.cs#L180

Then, each FIxedUpdate we set the velocity and angular velocity equal to (distance / time) to get the item's position to match the controller's position plus the initial offset of position and rotation. To see this in action, check out this old blog post: http://www.vrinflux.com/newton-vr-physics-based-interaction-on-the-vive/

However, we've had a variety of issues with simply distance/time which I suspect is do to the position of the transform not being updated quite inline with the position of the rigidbody.
See here: https://github.com/TomorrowTodayLabs/NewtonVR/blob/master/Assets/NewtonVR/NVRInteractableItem.cs#L88

So what I'm trying to do is translate the "create a transform" solution to a more math based approach that solely relies on Rigidbody.position and Rigidbody.rotation. But I'm having some significant issues with that. On pickup I get a bunch of variables that might be helpful:

             PickupPointItem = this.Rigidbody.position;
             PickupRotationItem = this.Rigidbody.rotation;
             PickupPointHand = hand.Rigidbody.position;
             PickupRotationHand = hand.Rigidbody.rotation;
             PickupPointDiff = PickupPointHand - PickupPointItem;
             PickupRotationDelta = Quaternion.Inverse(PickupRotationHand) * PickupRotationItem;

Here's my current thought process for getting the deltas I need to apply the velocity:
For rotation I want to get the delta from the hand's initial rotation to the hands current rotation (currentHandRotationDelta). Then I want to apply that rotation to the initial rotation of the item (PickupRotationItem) to get the target rotation. Then the delta between the current rotation and that target rotation should be correct (but doesn't seem to be). Here's my code:

                 Quaternion currentHandRotationDelta = Quaternion.Inverse(PickupRotationHand) * AttachedHand.Rigidbody.rotation;
                 Quaternion targetRotation = PickupRotationItem * currentHandRotationDelta;
                 rotationDelta = Quaternion.Inverse(this.Rigidbody.rotation) * targetRotation;

Position is more complicated. I get the currentPickupPoint, which is the position on the object that the hand should have been over when it was first picked up. I calculate that by getting the point of the current item position plus the initial position delta and rotating that around the pivot of the current item position. Then I take the difference in position from that calculated point and the current rigidbody to get the global delta. Then I use that plus the current hand position as a point to rotate around the pivot of the hand by the rotation of the delta from the initial hand rotation to the current hand rotation. Here's the relevant code for that:

                 Vector3 currentPickupPoint = RotatePointAroundPivot(PickupPointDiff + this.Rigidbody.position, this.Rigidbody.position, Quaternion.Inverse(PickupRotationItem) * this.Rigidbody.rotation);
                 Vector3 currentDiff = this.Rigidbody.position - currentPickupPoint;
 
                 Vector3 targetPosition = RotatePointAroundPivot(AttachedHand.Rigidbody.position + currentDiff, AttachedHand.Rigidbody.position, Quaternion.Inverse(PickupRotationHand) * AttachedHand.Rigidbody.rotation);
 
 
                 positionDelta = targetPosition - this.Rigidbody.position;

Here's the RotatePointAroundPivot method:

         private Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
         {
             Vector3 dir = point - pivot; // get point direction relative to pivot
             dir = rotation * dir; // rotate it
             point = dir + pivot; // calculate rotated point
             return point; // return it
         }



Here's a link to the nonworking code on the development branch of our github repo: https://github.com/TomorrowTodayLabs/NewtonVR/blob/development/Assets/NewtonVR/NVRInteractableItem.cs This doesn't seem to be working at all :D But I'm not super sure why. I have no math training past basic algebra but I imagine this is relatively straight forward at higher math levels. What am I missing?

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion using global values instead of local. Please help :( 0 Answers

Using a VR controller as a joystick 0 Answers

[SOLVED]aligning rigidbody to be "level" with world's X and Z coords. How can I make sure it faces the same way (Y coord)? 0 Answers

How to make any dice have a given face(int) face up? 1 Answer

Object snapping to floor and other objects in VR 1 Answer


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