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 tevezisgod · Jun 10, 2012 at 02:04 PM · cameramoveadventure

Moving the camera "on rails"

Hi guys I'm making a point and click adventure game with unity, and I'm trying to set the environment to be "semi" realtime. What I mean is, I want the camera to move only when the mouse is clicked on specific areas in the scene. I tried to do it with animation, but the results were less than expected. What I want to do is move the camera with code, but I'm not sure how to do it. I managed to create a script which "teleports" the camera to the area I clicked, but can't manage to make it move there smoothly. Thanks in advance.

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
2

Answer by Setzer22 · Jun 10, 2012 at 02:13 PM

Well, you could just simply modify the transform.position of the camera over time. Also using functions like Lerp or SmoothDamp could make that more easy.

I assume your code changes the transform.position of your camera to the new desiredPosition, like that

 transform.position = desiredPosition

What you could do instead, is to linearly interpolate between the two vectors over time

 function Update(){
    transform.position  Vector3.Lerp (transform.position,desiredPosition
                                      Time.deltaTime * timeInSeconds);
 }

This will gradually move your camera over time, so it gets to the desiredPosition (wich has to be a vector3) in the time of timeInSeconds (which should be a float)

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 syclamoth · Jun 10, 2012 at 02:11 PM

If you can manage a teleport, you can manage a smooth transition.

Teleport script:

 void PortToPosition(Vector3 targetPos)
 {
     transform.position = targetPos;
 }

Call this like so:

 PortToPosition(place to go to);

If you want it to move smoothly, replace it with this function:

 IEnumerator SlideToPosition(Vector3 targetPos, float time)
 {
     // Use an animation curve to make it look sweet!
     AnimationCurve smoothly = AnimationCurve.EaseInOut(0, 0, 1, 1);
     Transform myTrans = transform; // cache the transform for extra efficiency!
     float curTime = 0;
     Vector3 startPosition = myTrans.position;
     while(curTime < time)
     {
         myTrans.position = Vector3.Lerp(startPosition, targetPos, smoothly.Evaluate(curTime / time));
         curTime += Time.deltaTime;
         yield return null;
     }
      myTrans.position = targetPos;
 }

Call it like this:

 StartCoroutine(SlideToPosition(place to go, time to take));
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 syclamoth · Jun 10, 2012 at 02:11 PM 0
Share

Adapting this to manage rotation as well is pretty straightforward.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

camera move on unity 1 Answer

how to make camera to center the dynamically placed objects? 1 Answer

Moving an object in camera direction? 1 Answer

Orienting the camera above the player when Locked on 1 Answer

show a camera in one monitor and another camera in another monitor 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