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
1
Question by mrttson · Sep 12, 2017 at 03:54 PM · vr

Orbit camera for VR Cardboard

I'm trying to make a 3rd person camera controller for using Google VR sdk, but i face a problem when moving camera to keep it looking at Player object

alt text

My scene structure like this:

--- Player

--- CameraContainer

------ MainCamera

How can i calculate the position of CameraContainer base on Rotation of MainCamera to keep Player object always between the center of camera

The problem same with bellow question but i need move CameraContainer base on rotation of MainCamera

https://forum.unity.com/threads/rotate-the-camera-around-the-object.47353/

====================================================================

Update:

I'm using this script to move camera positon but it works with Mouse Input, any idea to convert it using MainCamera rotation?

 public class CameraFollow : MonoBehaviour {
 
     public Transform target;
     float distance = 10f;
     int cameraSpeed = 5;
     float xSpeed = 175f;
     float ySpeed = 75f;
     int yMinLimit = 20;
     int yMaxLimit = 80;
 
     int minDistance = 5;
     int maxDistance = 20;
 
     float x = 0f;
     float y = 0f;
 
 
 
     // Use this for initialization
     void Start () {
         var angles = transform.eulerAngles;
         x = angles.y;
         y = angles.x;
 
         // Make the rigid body not change rotation
         var rigidbody = GetComponent<Rigidbody>();
         if (rigidbody)
             rigidbody.freezeRotation = true;
     }
     
     // Update is called once per frame
     void LateUpdate () {
         
 
         //Zooming with mouse
         distance += Input.GetAxis("Mouse ScrollWheel") * distance;
         distance = Mathf.Clamp(distance, minDistance, maxDistance);
 
         //Detect mouse drag;
         if (Input.GetMouseButton(0))
         {
 
             x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
             y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
         }
         y = ClampAngle(y, yMinLimit, yMaxLimit);
 
         var rotation = Quaternion.Euler(y, x, 0);
         var position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position;
 
         transform.position = Vector3.Lerp(transform.position, position, cameraSpeed * Time.deltaTime);
         transform.rotation = rotation;
     }
 
     float ClampAngle(float angle, float min, float max)
     {
         if (angle < -360)
             angle += 360;
         if (angle > 360)
             angle -= 360;
         return Mathf.Clamp(angle, min, max);
     }
 }

untitled.png (13.4 kB)
Comment
Add comment · Show 4
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 hexagonius · Sep 14, 2017 at 05:00 AM 0
Share

Let an empty gameobject follow the player, matching his position. Attach the camera to it. Rotate the empty based on cardboard orientation.

avatar image mrttson hexagonius · Sep 15, 2017 at 02:08 AM 0
Share

@hexagonius Thanks for reply! How can i calculate the position of empty gameobject based on VR camera rotation? Because when VR camera rotated, i have to change the position of empty gameobject localy around Player

avatar image hexagonius mrttson · Sep 15, 2017 at 02:14 PM 0
Share

Why? As I said, make the camera dependent on the empty, not the other way around.

Show more comments

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

93 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

Related Questions

How to fly in Controller's forward direction? 1 Answer

In VR camera.pixelWidth reports unity editor viewport size 0 Answers

Detail mesh looks black when it has not geometry behind (on OCULUS VR) 0 Answers

Is there a way to disable OVRplayerController tracking for use with networking such as Photon? (Oculus Integration) 1 Answer

SteamVR Input window not loading properly 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