Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AnJoBo · Aug 30, 2018 at 12:50 PM · camerarotationzoom

How do I rotate the camera upwards when zoom is close?

Hello. I'm trying to work on my CameraController script. Currently I'm attempting to rotate the camera upwards towards the "center" of my player object when it's close.

I have my rotation and zoom controlled by sliders at the moment, and may change that in time (gearing towards mobile controls).

Reason why I want this is because when the zoom is all the way down the camera is looking at the feet of my player. Later on in development I'd like this close zoom to allow the player to look at their character and how they look from head to toe. I'd also like this to smoothly hit that spot as the zoom value drops.

Here is my code:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class CameraController : MonoBehaviour {
 public Transform player; // Access to the player object's Transform component
 
     public float camHeight;
     public float camDistance;
 
     public Slider zoomSlider; // Access to UI Zoom Slider
     public Slider rotateSlider; // Access to the UI Rotate Slider
 
     private float fov; // Set variable for field of view
     private Vector3 offset; // Set variable for camera offset/ position
     private Vector3 lookAngle;
     private GameObject[] roofs;
 
     void Awake ()
     {
         offset = new Vector3(player.position.x, player.position.y + camHeight, player.position.z - camDistance);
 
         roofs = GameObject.FindGameObjectsWithTag("Roof");
     }
 
     private void Update()
     {
         Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.45f));
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 100))
         {
             // Checks for seeing if player is inside
             if (hit.collider.CompareTag("Floor"))
             {
                 for (int i = 0; i < roofs.Length; i++)
                 {
                     roofs[i].SetActive(false);
                 }
             }
             else
             {
                 for (int i = 0; i < roofs.Length; i++)
                 {
                     roofs[i].SetActive(true);
                 }
             }
 
         }
 
     }
 
     void LateUpdate ()
     {
         if (Input.GetMouseButtonDown(0))
         {
             rotateSlider.minValue = rotateSlider.value - 180;
             rotateSlider.maxValue = rotateSlider.value + 180;
         }
 
         if (zoomSlider.value <= 10)
         {
             lookAngle = new Vector3(player.position.x, player.position.y + ANGLE TO LOOK UP, player.position.z);
         }
         if (zoomSlider.value > 10)
         {
             lookAngle = player.position;
         }
 
         transform.position = player.position + offset; // Sets camera offset
         transform.LookAt(lookAngle); // Look at player
         transform.RotateAround(player.position, Vector3.up, rotateSlider.value); // Rotate around player based on slider value
         fov = zoomSlider.value;
         Camera.main.fieldOfView = fov;
 
     }
 
 }


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

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

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

Related Questions

Camera Zoom from rotation. 0 Answers

Basic Camera rotation and Zoom 0 Answers

Need help implementing a zoom function 0 Answers

Local Third Person Movement based off Camera Rotation 0 Answers

Rotate according to the camera on Y and Z only! 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