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 DanaScully · May 23, 2017 at 11:39 AM · camerarotationtilting

Rotate Camera to a position and rotate back

I am pretty new to unity and I want to rotate my camera to a random position and then rotate it back to it's original rotation. for now I just compute a random vector and apply rotation speed to it. But It does not return to it's original position and keeps rotating. The goal is to rotate the camera and rotate it back.

    public Camera cam;
     public Transform obj;
 
     public float rotationSpeed = 0.5f;
     Transform camPos;
     Transform mainPos;
     float camPitch = 0.0f;
     bool val = true;
     Vector3 rotationPos;
     void Start()
     {
         camPos = cam.GetComponent<Transform>();
         mainPos = camPos;
         rotationPos = new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
     }
 
     void LateUpdate()
     {
        
         if(camPitch < 20)
         {
             camPitch += rotationSpeed;
             camPos.Rotate(rotationPos*rotationSpeed);
         }
         else 
         {
             camPos.Rotate(mainPos.position * rotationSpeed);
         }
         
 
         
     }
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 Ark_Revan · May 23, 2017 at 12:43 PM

One way to do that, is to use a kind of timer.

as a global var

 public float totalTime;
 private float startTimer = 0;

and in the update

 if(startTimer == 0){
        startTimer = Time.time;
 }
 if(Time.time < totalTime/2){
         //apply the velocity to rotate
 }else if(Time.time > totalTime/2){
         //apply -1*velocity to rotate
 }else if(Time.time > totalTime){
         startTimer = 0;
 
 }


Comment
Add comment · Show 4 · 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 DanaScully · May 23, 2017 at 01:53 PM 0
Share

Thanks for the help! This indeed does rotate to the new position but it doesn't return to the original position and rotate again to a new position.

avatar image Ark_Revan DanaScully · May 23, 2017 at 02:25 PM 0
Share

Did you wrote something like this in the first comment

 float rotHorizontal = 1 * rotateSpeed * Time.deltaTime;
         Camera.main.transform.Rotate(0, rotHorizontal, 0, Space.World);

and this in the second comment ?

 float rotHorizontal = -1 * rotateSpeed * Time.deltaTime;
         Camera.main.transform.Rotate(0, rotHorizontal, 0, Space.World);


you might need to change the axis in the rotation.

avatar image DanaScully Ark_Revan · May 24, 2017 at 08:21 AM 0
Share

Hi. Not exactly that but similar. I am a bit confused now because what i want to do is similar to a state machine. rotate, wait, rotate back to original pos, and repeat this process. I might consider using the animation

Show more comments

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

107 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

Related Questions

How to freeze the rotation or the position on the camera transform? 1 Answer

FPS camera movement breaks GameObject 2 Answers

Problem with wave like movement when rotating around X and Y axis with mouse input // Please Close/Delete 1 Answer

Getting the camera to look at a direction? 1 Answer

How to fix weird camera rotation? 0 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