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 /
avatar image
0
Question by Guy_Yome · Sep 30, 2014 at 01:54 AM · rotationpositionanglerelative

Position from rotation problem.

I have a question I searched about and couldn't find. Sorry if there is already an answer. So, I have a GameObjet that is a wall that can have a rotation over the Y axis. In the script of this object, I have a node that can move around ( technically the player ). I want to find the position in X,Y,Z relative of the wall to the node. It already works if the Y rotation is 0. With those informations I want to display another node that is symtrical to the node on the other side of the wall. But I don't want it to be like a mirror. Right on one side of the wall is also right on the other side. I can show my code and I also know where I need to change the code, because it's already working, but not when I change the Y angle. Sorry but my variables are in french. Thanks for any help.

 var cameraRelativeMur = objMurLiaison.transform.InverseTransformPoint( objCameraJoueur.transform.position );
     cameraRelativeMur = cameraRelativeMur + Vector3( 0, -1 * cameraRelativeMur.y, -1 * cameraRelativeMur.y );
     print( 'rel : ' + cameraRelativeMur );

     // The 3 next lines are the one to change
     // À modifer pour être en lien avec la rotation
     var distanceX = 1 * ( positionPointMur.x - objCameraJoueur.transform.position.x );
     var distanceY = 1 * ( positionPointMur.y - objCameraJoueur.transform.position.y );
     var distanceZ = 1 * ( positionPointMur.z - objCameraJoueur.transform.position.z );
     
     print( 'abs : (' + distanceX + ',' + distanceY + ',' + distanceZ + ')' );
     var distXRel = ( distanceX * objMurLiaison.transform.right );
     var distYRel = ( distanceY * objMurLiaison.transform.forward );
     var distZRel = ( distanceZ * objMurLiaison.transform.up );
     
     var distRel = distXRel + distYRel + distZRel;
     
     transform.position = objMurLiaison.transform.position + distRel;
     
     var directionSym = -1 * ( ( nodeObjCameraJoueur.transform.position ) - objCameraJoueur.transform.position );
     directionSym -= Vector3( 0, directionSym.y * 2, 0 );
     transform.rotation = Quaternion.LookRotation(directionSym);
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Sep 30, 2014 at 03:39 AM

If your wall is symmetrical around the pivot, can't you just rotate 180 degrees. That is, you place your second 'node' at the same position as the first and then do:

  transform.RotateAround(wall.position, wall.up, 180);
Comment
Add comment · Show 3 · 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 Guy_Yome · Oct 01, 2014 at 01:13 AM 0
Share

You sir, are a great sir! It worked! But at first it wasn't doing so because I forgot that I rotated the wall on the X axis because it was a plane. So, the axis argument in the RotateAround function you wrote what in fact forward not up.

avatar image robertbu · Oct 01, 2014 at 03:02 AM 0
Share

If you are using planes for walls, consider changing to Quads. A plane has 121 vertices and 200 triangles. A Quad has 4 vertices and 2 triangles. In addition, a Quad is vertical when the rotation is (0,0,0).

avatar image Guy_Yome · Oct 01, 2014 at 11:11 PM 0
Share

Well, polygon economy, won't say no to it. Thanks. I didn't know that the sides worked like a plane ( the normals ).

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

2 People are following this question.

avatar image avatar image

Related Questions

How to use the lerp function with rotation? (C#) 1 Answer

Relative Rotation 1 Answer

blocks being placed in an odd way 0 Answers

LocalScale and Rotation problem (work in Inspector but not in script) 1 Answer

How to get offset postition after rotation ? (Spent hours figuring it out) 3 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