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 jpcoder · Mar 02, 2013 at 05:41 PM · camerasmooth follow

Switch Smooth Follow between targets smoothly

I have a Smooth Follow script on my main camera. This works fine. Now, I would like to switch between two targets and have the camera move smoothly between the two target and then resume following the second target. How might I accomplish this? I have tried Lerping between the two and that did not seem to work but I may just be doing it wrong. Thanks...

Comment
Add comment · Show 4
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 hoy_smallfry · Mar 02, 2013 at 05:50 PM 0
Share

what kind of behavior did you get when you lerped?

avatar image jpcoder · Mar 02, 2013 at 05:54 PM 0
Share

I don't think it did anything. I took that code out though so I can try it now.

avatar image robertbu · Mar 02, 2013 at 06:14 PM 0
Share

what smooth follow script are you using, and is it a 3D or 2D game?

avatar image jpcoder · Mar 02, 2013 at 06:24 PM 0
Share

Using the Smooth Follow script that comes with Unity 3.5 and it is 3D.

1 Reply

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

Answer by robertbu · Mar 02, 2013 at 08:09 PM

I'm not happy with the code below, but it is all I have time for at the moment. It's based on the standard Smooth Follow. You need to Lerp() both the position and the LookAt rotation in order to get the smooth movement you want. Of course this will impact the general movement. Try it an let me know. There is another way to approach the problem (that does not involve modifying SmoothFollow).

 var target : Transform;
 var distance = 10.0;
 var height = 5.0;
 var rotationDamping = 3.0;
 var movementDamping = 1.0;
 
 function LateUpdate () {
     if (!target)
         return;
     
     var wantedHeight = target.position.y + height;
     var currentRotationAngle = transform.eulerAngles.y;
     var currentHeight = transform.position.y;
 
     currentRotationAngle = target.eulerAngles.y;
 
     var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
     
     var pos = target.position;
     pos -= currentRotation * Vector3.forward * distance;
     pos.y = wantedHeight;
     
     transform.position = Vector3.Lerp(transform.position, pos, movementDamping * Time.deltaTime);
     
     var q = Quaternion.LookRotation(target.transform.position - transform.position, Vector3.up);
     transform.rotation = Quaternion.Slerp(transform.rotation, q, rotationDamping * Time.deltaTime);
 }
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 jpcoder · Mar 02, 2013 at 08:23 PM 0
Share

That is EXACTLY what I needed! Thank you so much. I think when I tried it myself I wasn't doing the LookRotation Lerp. This works great!

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

10 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

Related Questions

The problem with the touch-control orbit view in the scene 0 Answers

Mouse orbit + Smooth follow script question 0 Answers

Improve smooth 2d side scroller camera to look more fluent 1 Answer

how can i make the main cam smooth follow a new prefab that i add after the game start . 5 Answers

How to make camera position relative to a specific target. 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