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
1
Question by Salman_Shh · Apr 19, 2015 at 10:18 PM · camerazoomzoom-in

Zoom in when player is accelerating/ if not zoom out

This is the code i have written - the player movement is fine but I can't get the orthographic size to lerp to Maximum Orthographic size/Minimum Orthographic size.

 using UnityEngine;
 using System.Collections;
 
 public class playerMovement : MonoBehaviour {
     //orthographic size for zoom Effect
     public float maxOrthographicSize = 40f;
     public float minOrthographicSize = 25f;
     public float Smoothing = 1f;
 
     public float maxSpeed = 200f; // Maximum speed - will be used to LIMIT PLAYER SPEED.
     public float aceleration = 5f; // Player acceleration Speed.
     public float rotateSpeed = 180f; // Player Rotation Speed
     bool onMove; // Use this to check for Player Input to Move Forward
 
     // Do GRAPHICS and INPUTS updates
     void Update () {
         //// ROTATING THE PLAYER SHIP
 
         // Grab our rotation quaternion
         Quaternion rotate = transform.rotation;
 
         // Grab the Z euler angle
         float z = rotate.eulerAngles.z;
 
         // Change the Z angle based on input
         z -= Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;
 
         // Recreate the quaternion
         rotate = Quaternion.Euler(0, 0, z);
 
         // Feed the quaternion into our rotation
         transform.rotation = rotate;
         
         // When The player is Holding Down the Input set the Boolean to "True".
         if (Input.GetButtonDown("Move")){
             onMove = true;
             AccelerationZoomOut();
         }
 
 
         // if the button is not being Held down the Boolean is set to "False".
         if (Input.GetButtonUp("Move")) {
             onMove = false;
             NoAccelerationZoomIn();
             
         }
     }
 
     // Do the Physics Engine updates here!
     void FixedUpdate() {
         //When the the Move Button is down then Player MOVES
         // if the Bool is False then the Rigidbody will fall
         if (onMove == true)
         {
             // Pushed Playership RIGIDBODY
             rigidbody2D.AddForce(transform.up * aceleration* Time.deltaTime);
 
             // limit the Player speed from turning into a torpedo
             rigidbody2D.velocity = Vector3.ClampMagnitude(rigidbody2D.velocity, maxSpeed);
            
 
         }
         
     }
 
     void AccelerationZoomOut()
     {
         //When Player is Accelerating the camera zooms out from the player
         Camera.main.orthographicSize = Mathf.Lerp(maxOrthographicSize, minOrthographicSize, Time.deltaTime * Smoothing);
     }
 
     void NoAccelerationZoomIn()
     {
         //When Player is not accelerating the camera zooms in to the player
         Camera.main.orthographicSize = Mathf.Lerp(minOrthographicSize, maxOrthographicSize, Time.deltaTime * Smoothing);
     }
 }

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 jessee03 · Apr 19, 2015 at 11:19 PM 0
Share

GetButtonUp is only going to call the function once, when you lift your finger off of the button. So I don't believe that's enough times to get your camera to lerp properly to it's position. I would just use on$$anonymous$$ove bool and do an if / else if statement in your Update function to call AccelerationZoomOut() and NoAccelerationZoomIn(). Would make it easier that way.

avatar image Salman_Shh · Apr 19, 2015 at 11:42 PM 1
Share

Thanks it worked @Jessee03

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use vuforia AR Camera for Zoom 1 Answer

Simple Camera ZoomIn Out Script 1 Answer

Camera Changing size fluidly depending on An Objects y position 0 Answers

Changing camera position to shoot through scope on gun 1 Answer

Lining up Fov's 0 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