• 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 ratboy · Feb 13, 2012 at 11:00 PM · camera2dzoomorthographic

2D camera zoom in comparison to the height of target

I have a 2d vehicle moving along a 2d surface, and the camera is orthographic, and follows the vehicle side on as it moves. I need the camera to zoom in and out a bit when the vehicle jumps over a ramp, so the higher it goes the further out the camera zooms, or rather changes orthographic size, and then reverts back when the vehicle lands again, with smoothing, is this possible?

cheers - monster.

Comment
Add comment · Show 3
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 AprendaGames · Feb 14, 2012 at 02:11 AM 0
Share
  1. Deter$$anonymous$$e the height your car is off the ground. You can do this with a raycast or another method depending on how your game is built.

  2. Deter$$anonymous$$e how high you expect your car to jump and the $$anonymous$$ and max size of the ortho.

Ex:

carHeight = 0 to 10

orthoSize = 10 to 50

orthoRange = 40 (50 $$anonymous$$us 10)

ratio = 4 (orthoRange/maxCarHeight)

orthoSize = carHeight * 4 + 10;

avatar image ratboy · Feb 14, 2012 at 01:13 PM 0
Share

thanks - this makes sense, but im afraid i lack the scripting knowledge to fully put this together (still a newbie) :p

im using a physics raycast to deter$$anonymous$$e the height so how would i put this together.. im just trying and failing again and again, im using JS if you could help out again :) cheers for the reply though!

avatar image ratboy · Feb 14, 2012 at 04:27 PM 0
Share

right ive worked out the body of the script, but how do I call in the 'carHeight' from the raycast on the gameobject, into the script on the camera? anybody?

2 Replies

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

Answer by Berenger · Feb 14, 2012 at 04:58 PM

It depends how you're making your camera moves, but I guess it's a child of the vehicle. So, when it jumps, the camera jumps to, changing it's heights, and you want the size to change as well. This is what I would do in a script attached to the camera :

 var : relativeHeight = (transform.position.y - minHeight) / (maxHeight-minHeight);
 camera.orthographicSize = Mathf.Lerp( minSize, maxSize, relativeHeight );

If you can find the correct values for min and max, it should work.

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 ratboy · Feb 14, 2012 at 07:23 PM 0
Share

thanks alot - works a treat, although dont have the camera as a child of the vehicle otherwise it rotates with the car too, but the script works fine, just need to tweak the values.

avatar image
0

Answer by ratboy · Feb 14, 2012 at 11:12 PM

right ive worked out the body of the script, but how do I call in the 'carHeight' from the raycast on the gameobject, into the script on the camera? anybody?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamic Orthagraphic Camera Zoom 1 Answer

Why is part of object outside camera frustum visible? 1 Answer

How do I adapt Brackey's Multiple Target Camera for a 2D game? 2 Answers

ortographic camera smooth follow with zoom 1 Answer

2d orthographic camera follow 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