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 /
This question was closed Dec 04, 2018 at 01:31 AM by WhisperXD for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by WhisperXD · Dec 03, 2018 at 06:11 PM · cameraplayerrotateeditaround

problem with rotate camera around player

i want to make camera rotate around player, but i can't edit the rotation or location, this my script. get touch :

     public Vector2 touchDist, pointerOld;
     protected int pointerId;
     public bool pressed;
 
     private void Update()
     {
         if (pressed)
         {
             if (pointerId >= 0 && pointerId < Input.touches.Length)
             {
                 touchDist = Input.touches[pointerId].position - pointerOld;
                 pointerOld = Input.touches[pointerId].position;
             }
             else
             {
                 touchDist = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - pointerOld;
                 pointerOld = Input.mousePosition;
             }
         }
         else
         {
             touchDist = new Vector2();
         }
     }
 
     public void OnPointerDown(PointerEventData eventData)
     {
         pressed = true;
         pointerId = eventData.pointerId;
         pointerOld = eventData.position;
     }
 
     public void OnPointerUp(PointerEventData eventData)
     {
         pressed = false;
     }

and this my script to rotate camera around player :

     public Camera mainCamera1;
     public FixedTouchField touchField;
     public float cameraDistancePlayer = 11, cameraPosYMax = 11, cameraPosYMin = 1, cameraAngleY, cameraPosY, cameraPosHSpeed = 0.1f, cameraPosYSpeed = 0.03f;
 
     private void Start()
     {
         cameraAngleY = -180;
         cameraPosY = 6.279997f;
     }
 
     private void Update()
     {
         cameraAngleY += touchField.touchDist.x * cameraPosHSpeed;
         cameraPosY = Mathf.Clamp(cameraPosY - touchField.touchDist.y * cameraPosYSpeed, cameraPosYMin, cameraPosYMax);
 
         mainCamera1.transform.position = transform.position + Quaternion.AngleAxis(cameraAngleY, Vector3.up) * new Vector3(0, cameraPosY, cameraDistancePlayer);
         mainCamera1.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2 - Camera.main.transform.position, Vector3.up);
     }

with this script i can rotate camera around player, but i can't edit rotation and location, is there a way to rotate the camera around the player but I can edit the location and rotation of the camera ??, maybe it can use vector or something ??

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 DJT4NN3R · Dec 03, 2018 at 07:13 PM 0
Share

Are you trying to make the camera move as the player swipes? If so, try something like this:

     float angle = 0;
     float yPosition = 0;
     float[] yClamps = new float[2] { y$$anonymous$$in, y$$anonymous$$ax }; // the $$anonymous$$ and max height values for your camera
     float distance; // the distance you want the camera to be from the target
     float[] sensitivity = new float[2] { xSensitivity, ySensitivity }; // the sensitivity to apply to the players touches
     Camera camera; // the camera
     Vector3 targetPosition; // the position in world space of your target

     void Update
     {
         // get the x distance between old and new touch and add it to the rotation angle
         angle += (camera.ScreenToViewportPoint(oldTouch).x - camera.ScreenToViewportPoint(newTouch).x) * sensitivity[0];
         // wrap the angle between 0 and 360
         if (angle > 360) angle -= 360;
         else if (angle < 0) angle += 360

         // get the y distance between old and new touch and add it to the y position
         yPosition += (camera.ScreenToViewportPoint(oldTouch).y - camera.ScreenToViewportPoint(newTouch).y) * sensitivity[1];
         // clamp the y position
         yPosition = $$anonymous$$athf.Clamp(yPosition, yClamps[0], yClamps[1]);

         // use the angle to calculate a point using cosine and sine, then add the height value to it, then normalize it to the desired distance
         camera.transform.position = new Vector3($$anonymous$$athf.Cos(angle * $$anonymous$$athf.Deg2Rad), yPosition,  $$anonymous$$athf.Sin(angle * $$anonymous$$athf.Deg2Rad)).normalized * distance;
         // make the camera look at the target
         camera.transform.LookAt(targetPosition);
     }
avatar image WhisperXD DJT4NN3R · Dec 04, 2018 at 01:30 AM 0
Share

thans, just like what i want,,

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Related Questions

How to Rotate Camera around GameObject (Player) 0 Answers

Rotate camera and player to face object 0 Answers

Mouse control rotate around player 0 Answers

SideScroller Rotate 1 Answer

Camera move belong a certain path 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