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 usagi · Nov 18, 2011 at 11:42 PM · camerarotationsmoothtranslation

Move and rotate the camera at the same time

Hi, I'm quite new about unity and I cannot figure out how to make my camera move and rotate at the same time when I click a specific button on my interface.

Let me explain more in detail what I need.

I've added a GUI interface in my project and when I press a specific button, I want that my camera makes a smooth movement while adjusting its rotation (and maybe its field of view). The problem is that all those translations and rotations happen along more than one axes:

  • start position (0,800,610)

  • start rotation (55,180,0)

  • final position (-200,800,1000)

  • final rotation (45,150,0)

I've found a lot of information about how to make GameObjects move or rotate using mouse coordinates, but not one matched my need. Does someone know how to solve this problem with a script?

EDIT:

this is the function I wrote

 function CameraMovement()
 {
    var startTime = Time.time;
    var startPoition = movementTarget.transform.position;
    
    var targetPosition = GameObject.Find("main_cam").transform.position;
    
    while (Time.time<startTime+1.5)
    {
       var i=(Time.time - startTime);
       movementTarget.transform.position = Vector3.Lerp(startPosition, targetPosition, i);
       yield;
    }
 }

It is triggered by one of the buttons in my GUI and it realize only a smooth translation. Do you know how can I improve it to have also the rotation?

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
0

Answer by kromenak · Nov 21, 2011 at 05:52 PM

The method you are using here to translate the movement target is entirely in world space, which is good because if the object rotates, that won't affect its movement direction.

You can Lerp rotation in a similar way to how you are Lerping the position. Check out Quaternion.Lerp and Quaternion.Slerp (http://unity3d.com/support/documentation/ScriptReference/Quaternion.html). You can then lerp from a current rotation to a new rotation.

If you are unsure how quaternions work, you can probably get by without knowing the internals of it all. There are a few static Quaternion functions that you can use to create a quaternion that represents a rotation direction. For example, Quaternion.Euler(x,y,z) will give you a Quaternion that represents a rotation with the given x,y,z angles.

You could then say something like

movementTarget.transform.rotation = Quaternion.Slerp(startRotation, endRotation, i);

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 usagi · Nov 28, 2011 at 10:20 AM

Thank you for the answer.

In the meanwhile I've found the iTween library, that is really easy to use and allows me to do the movements that I need.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Making a smooth camera translation and rotation, C# 1 Answer

Smooth Attached Object movement 1 Answer

How Can I Smooth This Camera Code 0 Answers

How to obtain perfect smooth rendering? 0 Answers

Smooth transform position and rotation 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