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 JPB18 · Aug 13, 2012 at 04:08 PM · camerajavascriptmousetransitionorbit

Smooth transition of camera targets

Hi there!

So, I'm make a Space RTS (more like a Space Combat Simulator) with diferent type of fighting objects (Ships, Fighters, Stations, etc.) and the player will have the need of switching the view between them, which may be thousands of meters appart from each other. As such making a sudden transition, would be visually unpleasant.

I'm already using the Mouse Orbit script from the standard assets, adapted to allow Zooming In and Out of the target (using the Mouse ScrollWheel Input).

So, how could I make a "yielded", lerp transition, keeping stuff like camera distance and orientation identical?

Thanks in advance.

João Borrego

Comment
Add comment · Show 2
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 Punkjim420 · Aug 13, 2012 at 04:42 PM 0
Share

if you look at the SmoothFollow script youll see rotation damping and height damping on the camera, forcing a smoothed "slide to position." You could try to copy that idea and tweak it to fit how you want?

avatar image JPB18 · Aug 13, 2012 at 04:45 PM 0
Share

Hmm I'll check it out... I'll tell you later out it worked out...

2 Replies

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

Answer by ScroodgeM · Aug 13, 2012 at 06:19 PM

one of thousands of ways to achieve that:

all below is to improve camera control script

  • declare a value that will store a object (X) or position that camera should observe from (station, ship, etc - transform is better cause you will follow the object on it's movings)

  • in Update() method, compare distance from camera to (X) and smooth move camera to this position (see below)

  • depends on previous check of movement needed and your gameplay, apply or not other camera controls (want you to control camera while it moving?)

some good methods to move camera smoothly:

  • move it by 0.1-0.5 of distance per second. this will move camera fast at start and slow on close to finish

  • move camera by 0.1-1 of distance stored before moving starts. this will move camera linear

  • move camera using AnimationCurve - so you can customize camera moves as you wish. for example, like elevators - slow accelerating and break, but fast movement between it

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 JPB18 · Aug 13, 2012 at 07:35 PM 0
Share

Thanks for the help! However, all that took some work :-P

avatar image
0

Answer by Dragonlance · Aug 13, 2012 at 06:58 PM

Well in my space game I give the object a camera position empty game object and a lookat empty game object (yould be in front or above of it)

Then I let this run on the camera: bool stateReached = false; Transform currentLookAt; Transform currentTargetTransform; ...

             // Perform Rotation
  Quaternion rotation = Quaternion.LookRotation (currentLookAt.position - transform.position);
  transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime);
             // Transform
  if (!stateReached) {
  // Transform Position
  transform.position = Vector3.Lerp (
  transform.position,
  currentTargetTransform.position,
  Time.deltaTime);
  if (Vector3.Distance (transform.position, currentTargetTransform.position) < 0.1f) {
  stateReached = true;
  }
  } 


I only need to reassign the currentLookAt and currentTargetTransform and the cammara starts flying there. If it is arrived and the target moves is smoothely follows. You could even temporary assign an enemy as currentLookAt (to follow your current traget or something)

This is just a snipped, but it should work out of the box. Maybe you need to add checking for null pointers etc. I stripped that out.

Of yourse you can do this yielded too with while(!stateReached) but the cammera will stop acting smooth after arriving.

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

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

Mouse Orbit snapping issues 0 Answers

camera orbit on mouse drag 2 Answers

Camera Orbit on Left Click problem 0 Answers

Move Camera According to Mouse Movement While Button is Pressed 1 Answer

Need help with a mouse orbit script 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