• 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 wwsamson · Aug 12, 2014 at 02:51 PM · cameracamera-lookflight sim

Camera zooms farther out when accelerating, in when decelerating, returns to normal when not accelerating?

I'm making a flight simulator and everything is working out fine, but the camera chase is really bugging me. I the camera coded to move away from the plane when I was at a higher speed and move in at a lower speed. The problem is, when the plane goes too fast, the camera moves so far away that the plane is practically unseeable. I considered having a limit for how far the camera could be away from the plane, but then when the plane accelerated beyond a speed that would be in the limit, it wouldn't really show in the camera chase.

Here is the code that I am using:

 Vector3 moveCamTo = transform.position - transform.forward *10.0f + Vector3.up * 5.0f;
         float bias = 0.96f;
         Camera.main.transform.position = Camera.main.transform.position * bias +
                                          moveCamTo * (1.0f-bias);
         Camera.main.transform.LookAt (transform.position + transform.forward * 30.0f);
 

I want to have the camera move in only when the plane is accelerating and move out only when it is deaccelerating, and when it is at a constant speed, it will return to the original position (move in if it is far out, move away if it is too far in) but I have no idea how to code this.

I'd greatly appreciate any help.

Thanks!

-wwsamson

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 smoggach · Aug 12, 2014 at 03:03 PM

I'd split it into two scripts. One script will constantly figure out where it wants the camera to be and the other will actually move the camera. Apply your limits to the first script. In the script that moves the camera you can constantly LERP towards where the first script wants you to be but never actually get there. This way if you're accelerating the camera will still move the whole time but also adhere to the limit. Then you can perform some logic to figure out when you're at a constant enough speed and lock the camera position.

It's going to be complicated in any case. Consider using an FSM

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 wwsamson · Aug 13, 2014 at 09:29 PM 0
Share

When the W key is pressed the plane will accelerate, and when the S key is pressed the plane will deaccelerate...perhaps there is some simpler way so that when W is pressed the camera will move in and when S is pressed it will move out? I'm relatively new to Unity and coding in general, so I'd appreciate help with the coding. Thanks!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Line problem 0 Answers

Player camera targeting/locking another object 0 Answers

Enable the OrbitCam script how can I make it will continue from the current camera view and position ? 0 Answers

Camera gets stuck when cursor is locked 0 Answers

Camera movement and gun follow in unity 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