• 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 /
  • Help Room /
avatar image
0
Question by sirimat · Aug 28, 2021 at 09:38 AM · oculus

Realign character controller with OVRCamera rig

Hi to everybody.

This is my first post here. I'vr got the following problem: i am using the latest oculus integration package and unity 2021. I have an OVRPlayerController in my scene, i've used the prefab in the oculus locomotion scene. The problem is that when i move the head (by physicalli walking in my scene) the capsule of the character controller iss not moving accordingly. So the problem is that if i walk some steps in the physical worldwhile i am wearing my HMD, and then, i move with the joystick inside the simulation, the capsule collider of the character controller is not aligned with my head and i am colliding with objects or penetrating them.

I've found somebody that says to add the camera constraint script but nothing changes.

What should i do?

this is the script that i am using to teleport. I can not figure out how to realign character capsule collider and the camera rig after teleport. in this way i always have bad collisions because the head and the body are not aligned. I have also tried to add Code (CSharp):

 OVRManager.display.RecenterPose();

in the After teleport method. This partially works because it realign the camera rig with the character capsule but it cause to ignore head rotation while teleporting.

Please help me

Code (CSharp):

 public class Teleporter : MonoBehaviour{
         [Header("Object to Teleport")]
         public GameObject teleportObject;
  
         public GameObject cameraRig;
  
         [Header("Aim Settings")]
         [Tooltip("The Object to Shoot the Beam From")]
         public Transform aimer;
         [Tooltip("Layers You Can Teleport On")]
         public LayerMask layer;
         [Tooltip("The Maximum Slope You Can Teleport On")]
         public float maxSurfaceAngle = 45;
         [Min(0)]
         public float distanceMultiplyer = 1;
         [Min(0)]
         public float curveStrength = 1;
         [Tooltip("Use Worldspace Must be True")]
         public LineRenderer line;
         [Tooltip("Maximum Length of The Teleport Line")]
         public int lineSegments = 50;
    
         [Header("Line Settings")]
         public Gradient canTeleportColor = new Gradient(){ colorKeys = new GradientColorKey[] { new GradientColorKey(){ color = Color.green, time = 0 } } };
         public Gradient cantTeleportColor = new Gradient(){ colorKeys = new GradientColorKey[] { new GradientColorKey(){ color = Color.red, time = 0 } } };
  
         [Tooltip("This gameobject will match the position of the teleport point when aiming")]
         public GameObject indicator;
  
  
  
         Vector3[] lineArr;
         bool aiming;
         bool hitting;
         RaycastHit aimHit;
        
      
  
         private void Start() {
             lineArr = new Vector3[lineSegments];
         }
  
         void Update()
         {
            
             if (aiming)
             {
                 CalculateTeleport();
             }
             else
                 line.positionCount = 0;
  
             DrawIndicator();
            
         }
  
         void CalculateTeleport() {
             line.colorGradient = cantTeleportColor;
             var lineList = new List<Vector3>();
             int i;
             hitting = false;
             for(i = 0; i < lineSegments; i++) {
                 var time = i/60f;
                 lineArr[i] = aimer.transform.position;
                 lineArr[i] += transform.forward*time*distanceMultiplyer*15;
                 lineArr[i].y += curveStrength * (time - Mathf.Pow(9.8f*0.5f*time, 2));
                 lineList.Add(lineArr[i]);
                 if(i != 0) {
                     if(Physics.Raycast(lineArr[i-1], lineArr[i]-lineArr[i-1], out aimHit, Vector3.Distance(lineArr[i], lineArr[i-1]), layer)) {
                         //Makes sure the angle isnt too steep
                         if(Vector3.Angle(aimHit.normal, Vector3.up) <= maxSurfaceAngle){
                             line.colorGradient = canTeleportColor;
                             lineList.Add(aimHit.point);
                             //Debug.Log(aimHit.point);
                             hitting = true;
                             break;
                         }
                         break;
                     }
                 }
             }
             line.positionCount = i;
             line.SetPositions(lineArr);
            
         }
  
         void DrawIndicator() {
             if(indicator != null){
                 if(hitting){
                     indicator.gameObject.SetActive(true);
                     indicator.transform.position = aimHit.point;
                     indicator.transform.up = aimHit.normal;
                 }
                 else
                     indicator.gameObject.SetActive(false);
             }
         }
  
         public void StartTeleport() {
             aiming = true;
         }
  
         public void CancelTeleport() {
             line.positionCount = 0;
             hitting = false;
             aiming = false;
         }
  
         public void Teleport() {
             Queue<Vector3> fromPos = new Queue<Vector3>();
             var teleportGuards = FindObjectsOfType<HandTeleportGuard>();
             foreach(var guard in teleportGuards) {
                 if(guard.gameObject.activeInHierarchy)
                     fromPos.Enqueue(guard.transform.position);
             }
             if(hitting) {
                 if (aimHit.collider.gameObject.tag == "Hotspot")
                 {
                     teleportObject.GetComponent<CharacterController>().transform.position = aimHit.collider.transform.GetChild(0).position;
                     //aggiunta MAT
                     //OVRManager.display.RecenterPose();
                 }
                 else
                 {
                    
                     teleportObject.GetComponent<CharacterController>().transform.position = aimHit.point;
                     //aggiunta MAT
                     //OVRManager.display.RecenterPose();
  
  
                 }
                
                
             }
            
             foreach(var guard in teleportGuards) {
                 if(guard.gameObject.activeInHierarchy) {
                     guard.TeleportProtection(fromPos.Dequeue(), guard.transform.position);
                 }
             }
             CancelTeleport();
             AfterTeleport();
         }
  
         void AfterTeleport() {
             var mainCam = Camera.main;
             //OVRManager.display.RecenterPose();
         }
     }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

166 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

Related Questions

Oculus DK2 0.5 SDK not working with Unity 5.0.4f1 with mac OSX 1 Answer

Unity 5.4.0f3 Oculus SDK2 Not working 2 Answers

Unable to merge Android manifests after making changes 0 Answers

THE OCULUS GO RESUME AND PAUSE PROBLEM WITH UNITY 0 Answers

Oculus: Works fine in editor but not working in build 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