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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by BennyRemi · Apr 27, 2020 at 11:10 AM · rotationperspective

same perspective view of 2 cubes with different position

Hello,


I´m developing a Profiler Tool in Unity VR and I have a problem where I need help. I will simplify my problem so it’s easier to understand.

I have two primitive cubes, let’s say cube A and Cube B. Cube A has always a Rotation of Vector3.zero. Cube B appears after a button click with a little distance in front of the Camera.

Now I want that Cube B has the same relative Rotation to my Main Camera (Camera that its attached to the head mounted display) as Cube A.

As Example: Imagine Cube A is at position (0,0,0) an the main Camera at (2,10,-10). Cube B (2,10,-9) is in front of the camera . Now when I look at Cube B, I have the same “perspective view” as if I look at cube A.


One of my ideas was to calculate the DeltaRotation of the forward Vectors:

 Vector3 lookDirectionCubeA = Camera.main.transform.position - cubeA.transform.position;
 Vector3 lookDirectionCubeB = Camera.main.transform.position – cubeB.transform.position;
 Quaternion deltaRotationCubeA = Quaternion.FromToRotation(CubeA.transform.forward, 
 lookDirectionCubeA);
 
 Quaternion deltaRotationCubeB = Quaternion.FromToRotation(cubeB.transform.forward, 
 lookDirectionCubeB);
 
  Quaternion diff = deltaRotationCubeB * Quaternion.Inverse(deltaRotationCubeA);

And use the lookAt Method:

 Vector3 forward = cubeB.transform.forward;    
 forward = diff * forward;
 cubeB.transform.LookAt(forward);

But that doesn't seem to work.

Thanks for every idea and help :)

Edit: For better understanding i took a view screenshots:

alt text

First img: Cube A and B have the same world Rotation.

alt text

Second Img: Now i want the cube B looks at the camera exact like cube A (I tried to rotate cube B in the Inspector for the screenshot)

annotation-2020-04-28-074942.png (52.4 kB)
annotation-2020-04j-28-074942.png (16.0 kB)
Comment
Add comment · Show 2
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 Bunny83 · Apr 28, 2020 at 01:04 AM 0
Share

I haven't really looked through your code. However I can see one thing that makes no sense, specifically this line:

 cubeB.transform.LookAt(forward);

The LookAt method takes a world space position as argument, not a direction. It works different from the LookRotation method in the Quaternion struct. The LookAt method is most likely implemented just like this internally:

 void LookAt(Vector3 worldPosition, Vector3 worldUp = Vector3.up)
 {
     this.rotation = Quaternion.LookRotation(worldPosition - this.position, worldUp);
 }

I really don't understand what you're actually asking. You talk about "same view" but it's unclear what you actually mean. You said cubeB is always not rotated so I assume cubeA can be rotated. However the whole relationship between the two cubes is not clear at all, at least to me.

avatar image BennyRemi Bunny83 · Apr 28, 2020 at 06:13 AM 0
Share

Im sorry that my question is unclear. But i added two screenshots, i hope its now more understandable. CubeA dont rotate, but Cube B can be rotated.

2 Replies

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

Answer by BennyRemi · May 26, 2020 at 09:36 AM

My solution so far: Create empty GameObject "G" as child on camera.

 G.transform.LookAt(cubeA.transform.position);
 GameObject copyOfCubeA = Instaniate(cubeA);
 copyOfCubeA.transform.parent = G.transform;
 G.transform.LookAt(cubeB.position);
 copyOfCubeA.transform.localPosition = new Vector3(0,0,distanceToCubeB);
 cubeB.transform.rotation = copyOfCubeA.transform.rotation;
 Destroy(copyOfCubeA);

I'm sure there is another solution without making a copy of CubeA and only manipulating the rotation of CubeB. But it works now for me :)

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 hexagonius · Apr 27, 2020 at 08:07 PM

If cube has 0 rotation, then it's relative rotation from the camera would be Quaternion.Inverse(camera.transform.rotation), which is the rotation you would give Cube B. Unless my assumption about what you are looking for is wrong. Because you do not answer the question from where the camera would be looking at A

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 BennyRemi · Apr 28, 2020 at 06:35 AM 0
Share

The Camera is attached to the H$$anonymous$$D and i can fly around. So at any position of the camera, i can set Cube B in front of the camera, and Cube B should have the same perspective for the Camera as Cube A.

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

164 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 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

Using a perspective camera can an object act as if viewed by orthographic camera? 1 Answer

My character is becoming distorted when looking around any ideas why this would happen? Also the view is inverted, can I change that? 1 Answer

First Person Camera Rotation Help 1 Answer

Flip over an object (smooth transition) 3 Answers

Trying to get a parented object to face the direction of the mouse pointer in a perspective view. 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