Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Sprawl · May 06, 2014 at 04:30 PM · rotationquaternion

Finding the rotation between two gameObjects

I'm working on a a similar mechanic to portals and I'm having some issues when the portals are not in the same angle. Basicly, once an object enters through the first portal, a copy is created in the second portal giving the illusion that is passes through. I'm having some issues when the portals have a different rotation. Here's a quick picture of the issue. alt text

Clearly The Quaternion i use to make the rotation in the mouvement is wrong, the Quaternion i use right now is this :

 Quaternion portalRotation =
  Quaternion.FromToRotation(LinkedPortal.transform.parent.rotation.eulerAngles,
  transform.parent.rotation.eulerAngles);



This code is on the portal itself and the LinkedPortal is the other portal that the objects are coming out of.

Here's the full code of the translation for anyone interested, though I'm pretty sure the issue is up there:

         Quaternion portalRotation = Quaternion.FromToRotation(LinkedPortal.transform.parent.rotation.eulerAngles, transform.parent.rotation.eulerAngles); // Rotation between portals
         Quaternion normalRotation = Quaternion.Euler(0,180,0); // Default Rotation of 180 degrees 
 
         //Update Position
         Vector3 pos = transform.position - player.transform.position; 
         pos = portalRotation * pos;
         pos = normalRotation * pos;
         pos = Vector3.Reflect(pos, (transform.up)); // Reflection to put clone on ground
         pos += LinkedPortal.transform.position;
 
         duplicate.transform.position = pos; //Assign Position
         duplicate.transform.localEulerAngles = rot; //Assign Rotation
         Debug.Log ("Quaternion:" + portalRotation);
         Debug.Log ("result:" + portalRotation * new Vector3 (0,0,1));
unityanswers-portal.png (15.4 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · May 06, 2014 at 06:30 PM

With questions like these, theirs never enough information because objects can be built in a variety of ways. Let's assume that this is 3D with the portals on the XZ plane, and that the blue side of each portal is the front side of the object (though my solution should work even if it is not). So the rotation should be:

 Quaternion q = Quaternion.FromToRotation(-LinkedPortal.transform.parent.forward, transform.parent.forward); 

You need to apply this rotation to your character's rotation (not assign it):

 character.transform.rotation = q * character.transform.rotation;

Note this assignment preserves the entry angle. That is, if the player enters at an angle, they will come out the new portal at the same angle.

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
avatar image
0

Answer by Jeff-Kesselman · May 06, 2014 at 04:41 PM

The simplest way to do this would be to express the angle as a vector local to the old portal's local space, and then transform that vector by the new portal's transform matrix to get the new direction vector in world space

Comment
Add comment · Show 1 · 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
avatar image Sprawl · May 06, 2014 at 04:54 PM 0
Share

It is what I'm trying to do. I'm trying to build that quaternion that I'm gonna transform my vector with. I've tried a few things and it doesn't work, what I have right now is this :

Quaternion.FromToRotation(newPortal.rotation, OldPortal.rotation)

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

21 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

Related Questions

Rotate Rigidbody to always face a force 0 Answers

Problem with normal snapping and rotations. 1 Answer

Relative rotation while moving on parent. 1 Answer

Rotate multiple objects around a object, maintaining their own trajectory(not rotating their local forward vector) 1 Answer

Smooth rotation about global axis instead of local axis. 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