Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Olaf.Bauer · Sep 05, 2014 at 09:53 AM · cameraoculus

Fly-Through using Unity and Oculus Rift

Hey all,

I'm currently trying to create a fly-through demo with Unity and Oculus Rift, where the user can virtually fly though a certain CAD model inside a small room. Everything is based on the OculusUnityIntegration.unitypackage, including all the assets and prefabs, most importantly the OVRPlayerController and OVRCameraController. So far, I kicked out the "unnecessary" code and disabled gravity. Furthermore, I have implemented a Jump_Up() and Jump_Down() method, which are used to ascend and descent the camera.

My problem now is that I'd like to always move in the direction of the camera when pressing W for forward, however I couldn't achieve that kind of movement yet. Basically it should be the same experience as in the Unity scene editor itself, where you can "fly" in direction of the camera when holding right mouse down and navigation via W,A,S,D.

I'm fairly new to both the Oculus SDK and game development in general, so any tips are appreciated!

I've made lots of different changes in the code, and I assume some changes are necessary to the OVRPlaerController.cs file, mainly to Update() or UpdateMovement():

 protected virtual void Update()
     {
         UpdateMovement();
 
         Vector3 moveDirection = Vector3.zero;
         
         float motorDamp = (1.0f + (Damping * OVRDevice.SimulationRate * Time.deltaTime));
         MoveThrottle.x /= motorDamp;
         MoveThrottle.y = (MoveThrottle.y > 0.0f) ? (MoveThrottle.y / motorDamp) : MoveThrottle.y;
         MoveThrottle.z /= motorDamp;
 
         moveDirection += MoveThrottle * OVRDevice.SimulationRate * Time.deltaTime;    
 
         moveDirection.y += FallSpeed * OVRDevice.SimulationRate * Time.deltaTime;
      
         Vector3 predictedXZ = Vector3.Scale((Controller.transform.localPosition + moveDirection), 
                                              new Vector3(1, 0, 1));    
         
         // Move contoller
         Controller.Move(moveDirection);
         
         Vector3 actualXZ = Vector3.Scale(Controller.transform.localPosition, new Vector3(1, 0, 1));
         
         if (predictedXZ != actualXZ)
             MoveThrottle += (actualXZ - predictedXZ) / (OVRDevice.SimulationRate * Time.deltaTime);
         
         // Update rotation using CameraController transform, possibly proving some rules for 
         // sliding the rotation for a more natural movement and body visual
         UpdatePlayerForwardDirTransform();
     }

 public virtual void UpdateMovement()
     {
         // Do not apply input if we are showing a level selection display
         if(HaltUpdateMovement == true)
             return;
     
         bool moveForward = false;
         bool moveLeft       = false;
         bool moveRight   = false;
         bool moveBack    = false;
                 
         MoveScale = 5.0f;
             
         // * * * * * * * * * * *
         // Keyboard input
             
         // Move
             
         // WASD
         if (Input.GetKey(KeyCode.W)) moveForward = true;
         if (Input.GetKey(KeyCode.A)) moveLeft     = true;
         if (Input.GetKey(KeyCode.S)) moveBack      = true; 
         if (Input.GetKey(KeyCode.D)) moveRight      = true; 
         // Arrow keys
         if (Input.GetKey(KeyCode.UpArrow))    moveForward = true;
         if (Input.GetKey(KeyCode.LeftArrow))  moveLeft       = true;
         if (Input.GetKey(KeyCode.DownArrow))  moveBack       = true; 
         if (Input.GetKey(KeyCode.RightArrow)) moveRight   = true; 
             
         MoveScale *= OVRDevice.SimulationRate * Time.deltaTime;
             
         // Compute this for key movement
         float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;
 
         if(DirXform != null)
         {
             if (moveForward)
                 MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
             if (moveBack)
                 MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
             if (moveLeft)
                 MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
             if (moveRight)
                 MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
         }
             
         // Rotate
 
         // compute for key rotation
         float rotateInfluence =  OVRDevice.SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;
 
         float deltaRotation = 0.0f;
         if(SkipMouseRotation == false)
             deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
             
         float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);
         YRotation += filteredDeltaRotation;
         sDeltaRotationOld = filteredDeltaRotation;   
         
         // Update cameras direction and rotation
         if (Input.GetKey(KeyCode.F))
         {
             Jump_Up();
             Jump_Up();
         }
         
         if (Input.GetKey (KeyCode.H)) 
         {
             Jump_Down ();
             Jump_Up();
         }
 
         SetCameras();
     }

Thanks a lot in advance!!

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 David Lind · Nov 26, 2014 at 05:37 AM 0
Share

Hey mate, did you have any luck with this? I'm also trying to achieve this!

avatar image GEWLAR · Nov 26, 2014 at 10:37 AM 0
Share

Have a look at the standard assets

You could just modify the First Person Controller

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Wisearn · Nov 26, 2014 at 11:00 AM

Ok so I don't know what else might be wrong with your code but you want to use the transform.up transform.right transform.forward insted of Vector3.up/right/forward

To get LEFT you do "minus transform.right"

 -transform.right

And same with backwards&down

Vector3.forward will give a "forward" direction that is independant of any rotation, transform.forward on the other hand will give you the direction that is forward of the transform (in this case your camera.transform)

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

Answer by usagi · May 01, 2015 at 01:01 PM

I'm also looking about adding flying capabilities to my camera and tried the last hint about using transfrom instead of Vector3 but I had no luck.

Any other suggestions?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Orthographic Camera 2 Answers

Disabling VR Camera rotation creates ''cinema'' effect in VR device 1 Answer

Draw texture directly on Oculus screen 1 Answer

How to use vuforia AR Camera for Zoom 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