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 GrimExp · Aug 13, 2018 at 08:38 AM · charactercontrollercamera rotatecamera-lookcamera rotationcamera.main

need a little help with my code camera rotation

so i'm working on the top down game for android but can't seem to get the camera to rotate on swipe from left to right can you guys help me with this because environment blocks the players video so i want them to be able to rotate the camera from right to left with swipe to be able to see in the direction they're heading i have tried so many different way to make this work but everything i've tried failed so can't you help me fix this

 using UnityEngine;
 
 [ExecuteInEditMode]
 public class FollowCamera : MonoBehaviour
 {
     private Transform cacheTransform;
     public Transform CacheTransform
     {
         get
         {
             if (cacheTransform == null)
                 cacheTransform = GetComponent<Transform>();
             return cacheTransform;
         }
     }
 
     // The target we are following
     public Transform target;
     public Vector3 targetOffset;
     [Header("Follow")]
     public float damping = 10.0f;
     public bool dontSmoothFollow;
     [Header("Look at")]
     public float lookAtDamping = 2.0f;
     public bool dontSmoothLookAt;
     [Header("Rotation")]
     public float xRotation;
     public float yRotation;
     [Tooltip("If this is TRUE, will update Y-rotation follow target")]
     public bool useTargetYRotation;
     [Header("Zoom")]
     public float zoomDistance = 10.0f;
     [Header("Zoom by ratio (Currently work well with landscape screen)")]
     public bool zoomByAspectRatio;
     public float zoomByAspectRatioWidth;
     public float zoomByAspectRatioHeight;
     public float zoomByAspectRatioMin;
 
     private void Update()
     {
         var targetPosition = target == null ? Vector3.zero : target.position;
         var targetYRotation = target == null ? 0 : target.eulerAngles.y;
         var wantedPosition = targetPosition + targetOffset;
         var wantedYRotation = useTargetYRotation ? targetYRotation : yRotation;
 
         // Convert the angle into a rotation
         var currentRotation = Quaternion.Euler(xRotation, wantedYRotation, 0);
 
         // Set the position of the camera on the x-z plane to:
         // distance meters behind the target
         wantedPosition -= currentRotation * Vector3.forward * zoomDistance;
 
         // Update position
         if (!dontSmoothFollow)
             CacheTransform.position = Vector3.Slerp(CacheTransform.position, wantedPosition, damping * Time.deltaTime);
         else
             CacheTransform.position = wantedPosition;
 
         // Always look at the target
         if (!dontSmoothLookAt)
         {
             Quaternion lookAtRotation = Quaternion.LookRotation(targetPosition + targetOffset - CacheTransform.position);
             CacheTransform.rotation = Quaternion.Slerp(CacheTransform.rotation, lookAtRotation, lookAtDamping * Time.deltaTime);
         }
         else
             CacheTransform.rotation = Quaternion.LookRotation(targetPosition + targetOffset - CacheTransform.position);
 
         if (zoomByAspectRatio)
         {
             var targetaspect = zoomByAspectRatioWidth / zoomByAspectRatioHeight;
             var windowaspect = (float)Screen.width / (float)Screen.height;
             var scaleheight = windowaspect / targetaspect;
             var diffScaleHeight = 1 - scaleheight;
             if (diffScaleHeight < zoomByAspectRatioMin)
                 diffScaleHeight = zoomByAspectRatioMin;
             zoomDistance = diffScaleHeight * 20f;
         }
     }
 
     private void LateUpdate()
     {
 #if UNITY_EDITOR
         // Update camera when it's updating edit mode (not play mode)
         if (!Application.isPlaying && Application.isEditor)
             Update();
 #endif
     }
 }

Comment
Add comment · Show 1
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 GrimExp · Aug 13, 2018 at 04:02 PM 0
Share

please help me

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GrimExp · Aug 13, 2018 at 06:22 PM

wow though i was going to get help quick but i was wrong

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

102 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

Related Questions

third person camera 2 Answers

Camera movement according to rotation and actual position RTS 1 Answer

camera zoom 1 Answer

Camera rotation 0 Answers

How to allow camera to complete an upside down rotation while using LookAt() 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