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 Kedrix · May 14, 2014 at 03:07 AM · camerarotationplaneview

How to pan-rotate camera transform parallel to its view plane?

Hello,

I tried tackling this problem for few days, but could not solve it.

So far I achieved a rotation along certain axis, but the desired effect is to rotate the camera along a circle-like path that is parallel to the camera's view "plane".

See the picture below:

alt text [1] .

Goal: achieving a rotation shown with a blue arrow-path (parallel to the camera's view plane)

Thanks.

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
Best Answer

Answer by robertbu · May 14, 2014 at 03:19 AM

Your question is missing details for me to give any focused answer:

  • What defines the center and radius of the circle

  • Does the camera need to rotate with the circle or does its orientation remain fixed.

  • What caused the camera to move on the path

Approaches:

  1. You can use RotateAround(). The axis of rotation would be the camera's transform.forward.

  2. Or you could make the camera a child of an empty game object on the same plane with an offset and rotate the child object.

  3. Or you can calculate the position based on a vector. You can use Quaternion.AngleAxis() to rotate the vector. Again transform.forward is the axis of rotation.

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 Kedrix · May 14, 2014 at 04:35 AM 0
Share

[What defines the center and radius of the circle] Circle's center I find by deducting a constant (int, that acts as a radius) from the last known X and Y.

From such I can find circle points on each of the degrees manually: nextX - new X coordinate that is the part of the circle path (without adjustment, which I don't know how to achieve yet)

cameraX - is the last known camera.transform.x

radius - is a constant that is manually defined

nextDegree - a value from 0.0f to 359.00f

**nextX = (cameraX - radius) + radius $$anonymous$$athf.Cos (nextDegree);* for Y is the same but with $$anonymous$$athf.Sin...

After having such I can make a Vector3(nextX, nextY, cameraZ), where cameraZ is the last known Z coordinate of the camera.

The whole point is camera transform was rotated in all 3 directions, making it less possible for me to use RotateAround, unless I am missing something.

I want to achieve a rotation parallel to the camera's view, but I cannot rotate the Z-axis with the camera, can I?

So as much as I understood I cannot use RotateAround function - it will not be "parallel" to the camera's view plane. (or once again I am missing on a point)

[Does the camera need to rotate with the circle or does its orientation remain fixed.] The blue arrow on phase 3 in the picture - is the path along which the camera would "slide/move/follow". So the circle (blue) - does not move, only the camera.

[What caused the camera to move on the path] I may not understand this question well, but I try answering it:

That's the effect I want to achieve. If you refer to the phases 1,2 of the picture - that's just a case of how the camera could be: 1) moved 2) rotated

So the main issue I have here is that "RotateAround" function will take the camera object and rotate it around the axis. But I need to rotate it in parallel to the camera's view plane (remember, I rotate the camera in all 3 directions, meaning that the camera's view plane is no longer parallel to any of the three axis)


You can use RotateAround(). The axis of rotation would be the camera's transform.forward.

Do correct me if I was wrong in the above comment to your answer, as I tried to do the rotation around the axis but I didn't have it working the way I wanted.

However, I will try doing it again just to ensure I had it right about, it was no way out for my case.

avatar image robertbu · May 14, 2014 at 04:57 AM 0
Share

but I cannot rotate the Z-axis with the camera, can I? -- So as much as I understood I cannot use RotateAround function - it will not be "parallel" to the camera's view plane

$$anonymous$$y suggestion is to use 'transform.forward' of the camera, not Vector3.forward. 'transform.forward' is the forward vector of the camera in world space. So if you use this as an axis of rotation, then the rotation will be parallel to the camera plane. Here is a bit of sample source. Do:

  • Start a new scene

  • $$anonymous$$ove and rotate the camera to some arbitrary position and angle.

  • Put a game object in front of the camera offset some from the center of the frame. This will be your center object.

  • Attach the following script to the camera.

  • Initialize the 'center' variable by dragging the object to be used as center onto the 'center' variable in the Inspector.

  • Hit play and use the arrow keys.

Note it will appear as if the object is circling, but in reality the camera is circling...on its view plane.

 #pragma strict
     
     var center : Transform;
     var speed = 90;  // Degrees per second
     
     private var v : Vector3;
     
     function Start() {
         v = transform.position - center.position;
     }
     
     function Update() {
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow)) {
             v = Quaternion.AngleAxis(speed * Time.deltaTime, transform.forward) * v;
             transform.position = center.position + v;
         }
            if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow)) {
             v = Quaternion.AngleAxis(-speed * Time.deltaTime, transform.forward) * v;
             transform.position = center.position + v;
         }
     }

As you can see from this example, the object dos not have to be on the camera plane, but it will work if it is.

avatar image Kedrix · May 14, 2014 at 05:23 AM 0
Share

It does what I was looking after. Thank you, I will have to remember that there also is "transform.forward" and not only Vectro3. ^^

But what bothers me now is that I did the same in my project where I needed it, and it does not work (until I simply created a new scene and basically followed a step by step instruction outlined by you).

That part, however, I would tackle further on my own, since I got the mechanics known to me by now.

I appreciate your help, thank you very much.

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

20 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

Related Questions

Rotate object relative to camera's view 2 Answers

largest reasonable camera view distance? 1 Answer

Camera Loop Rotation 0 Answers

Showing what the Camera sees on a plane 1 Answer

Rotating a plane so that its top is parallel to the camera viewport 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