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 Xxov3rxx · May 14, 2014 at 01:07 PM · cameramovementlerptopdownclamp

Camera Zoom script stops ability to pan

Hi guys sorry if this question seems noobish. I'm trying to get a camera script working. My game is a 3d top down and I want to be able to pan around the camera while being able to zoom in and out smoothly within a range. I got the panning to work fine but when I put the zoom functions in, the panning stops working. PS. Not sure if it matters the camera is child of the player object just so it can be a reference point to the zoom range.

Blockquote

using UnityEngine; using System.Collections;
public class CameraZoom2 : MonoBehaviour { public float moveSpeed= 60.0f; public float distance; private float sensitivityDistance = 50f; private float damping = 2.5f; private float min = 10; private float max = 50; private Vector3 ydistance;
void Start () { distance = -10f; distance = transform.localPosition.y; }
void Update () { //Camera Movement var x = Input.GetAxis("Horizontal") Time.deltaTime moveSpeed; var y = Input.GetAxis("Vertical") Time.deltaTime moveSpeed; transform.Translate(x, y, 0); //Camera Zoom distance -= Input.GetAxis("Mouse ScrollWheel") sensitivityDistance; distance = Mathf.Clamp(distance, min, max); ydistance.y = Mathf.Lerp(transform.localPosition.y, distance, Time.deltaTime damping); transform.localPosition = ydistance; } } Any help will be greatly appreciated! Thanks
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 $$anonymous$$ · May 14, 2014 at 02:18 PM 0
Share

$$anonymous$$aybe you are overwriting the camera position with this script.

I think its better to use the camera FieldOfView for zoo$$anonymous$$g in/out.

avatar image CodeElemental · May 14, 2014 at 02:28 PM 0
Share

Basically what @$$anonymous$$ said. If the camera is orthographic (which i assume it is since you are making a topdown game) then you can manipulate it's orthographicSize

avatar image Xxov3rxx · May 15, 2014 at 01:22 AM 0
Share

I can't use FOV because I want it to be 3d. I've tried FOV and when you get far away it stretches everything. Also yeah I think my camera zoom is fixed and overwriting something I just cant figure out how to reword it because I'm still very new to coding.

I'm trying to get the camera to move on xyz with lerp and clamp basically.

1 Reply

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

Answer by Xxov3rxx · May 15, 2014 at 05:43 AM

I figured it out. I'm not sure if this is the most practical way but I decided to make the camera the child of another empty object and I assigned the movement script to that empty object.

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

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

Related Questions

2D Orthographic camera movement clamp in any orthographic size 1 Answer

Camera move with mouse 0 Answers

How to smooth my camera (Vector3.Lerp) 0 Answers

Problems with Lerp. 1 Answer

Make a camera move towards player when the player moves out of the camera's vision 2 Answers


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