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 /
This question was closed Feb 26, 2014 at 10:09 AM by komodor for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by komodor · Feb 21, 2014 at 04:15 PM · camera2dfollowzoom

ortographic camera smooth follow with zoom

at http://answers.unity3d.com/questions/29183/2d-camera-smooth-follow.html i found pretty simplet and really nice working script for camera follow

 var dampTime : float = 0.3; //offset from the viewport center to fix damping
 private var velocity = Vector3.zero;
 var target : Transform;
  
 function Update() {
     if(target) {
         var point : Vector3 = camera.WorldToViewportPoint(target.position);
         var delta : Vector3 = target.position - camera.ViewportToWorldPoint(Vector3(0.5, 0.5, point.z));
         var destination : Vector3 = transform.position + delta;
  
        // Set this to the Y position you want the camera locked to
         destination.y = 0; 
  
         transform.position = Vector3.SmoothDamp(transform.position, destination, velocity, dampTime);
     }
 }

it's almost perfect i just need put camera.ortographic size there to be able to zoom simultaneously so i tried to change Z coordinate to ortographic size and i can't findout why it's nor working (actually it's zooming out all the time)

here's my current script:

     private void Update()
     {
         cameraPosition = new Vector3(target.x, target.y, camera.orthographicSize);
 
         Vector3 difference = camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0f)) + Vector3.forward*camera.orthographicSize;
         Vector3 delta = cameraPosition - difference;
         Vector3 destinationMovement = cameraPosition + delta;
 
         cameraPosition = Vector3.SmoothDamp(cameraPosition, destinationMovement, ref velocity, currentBoundaries.dampTimeMovement);
         transform.position = new Vector3(cameraPosition.x, cameraPosition.y, transform.position.z);
         camera.orthographicSize = cameraPosition.z;
     }
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

  • Sort: 
avatar image
0

Answer by zombience · Feb 21, 2014 at 04:30 PM

so, this is a bit of a hack, but one thing you might try is, if you know your final zoom points, create multiple cameras in your scene that have the zoom / view settings that you want.

for example, if you have a cube you're zooming in on, have a camera as a child of that cube, and arrange it so it is exactly placed where you want it, zoomed as you want. you can enable the camera in edit mode and preview it so it's set exactly as you want. you may then either disable the camera or have a script that disables the camera on game start.

then, when it is time to zoom to the cube, by some means or other (either GetComponentInChildren() or perhaps a general camera manager), grab the settings of that location camera and pass them to your current camera, and lerp to those new settings.

I've used this in a variety of scenarios and found it to be the best if you need very precise zoom locations. It even works on objects that are moving, since you can continually update the camera location to match the child camera which is focused exactly as you want it.

Hope that helps.

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 komodor · Feb 21, 2014 at 05:37 PM 0
Share

thank you for the suggestion, i definitely try it in some test project, but it's not my case - i have 2d scrolling game to do and only thing i need is to sync zoom with movement and fix bounding boxes for camera, right now it works but sometimes it makes weird stuff

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cinemachine 2d camera problem 0 Answers

Camera script 1 Answer

IPhone is zoomed in/out depending on which model 0 Answers

Smooth Camera 2D Follow Player 0 Answers

Shaky player effect when I apply a damping camera follow 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