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 Oct 09, 2017 at 09:42 AM by Morice1999 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Morice1999 · Sep 28, 2017 at 10:46 AM · camerarotationplayervrmovement script

Player walks in the direction the vr camera is looking?

I want that my player walks in the direction i look in Vr but when i turn my head i want my my character to move to there . so i mean where im looking is forward but i dont get. i tryed it almost a week now and i cant figure it our pls help. i have empty object tagged Player and a child of it is the Camera tagged MainCamera. the player has an Character Controller.

 void Update()
         {
             if (GvrControllerInput.IsTouching)
             {
                 ddTouchpadPos = GvrControllerInput.TouchPos;
                 if (ddTouchpadPos.y < 0.5f - deadZone)
                 {
                     normalizedDDTouch = new Vector3(0, 0, -0.08f);
                 }
                 if (ddTouchpadPos.y > 0.5f + deadZone)
                 {
                     normalizedDDTouch = new Vector3(0, 0, 0.07f);
                 }
 
                 if (ddTouchpadPos.x < 0.5f - deadZone)
                 {
                     normalizedDDTouch = new Vector3(0.07f, 0, 0);
                 }
                 if (ddTouchpadPos.x > 0.5f + deadZone)
                 {
                     normalizedDDTouch = new Vector3(-0.08f, 0, 0);
                 }
                 transform.localPosition += normalizedDDTouch;
             }
     }
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Hellium · Sep 28, 2017 at 10:56 AM

First of all, add a reference to the camera's transform :

  public Transform cameraTransform ; // Drag & drop here the transform of the camera rotated by the VR plugin

Then, use the local axies of the camera to move your object

              if (ddTouchpadPos.y < 0.5f - deadZone)
              {
                  normalizedDDTouch = Vector3.ProjectOnPlane( cameraTransform.forward, Vector3.up ) * -0.08f
              }
              if (ddTouchpadPos.y > 0.5f + deadZone)
              {
                  normalizedDDTouch = Vector3.ProjectOnPlane( cameraTransform.forward, Vector3.up ) * 0.07f
              }
 
              if (ddTouchpadPos.x < 0.5f - deadZone)
              {
                  normalizedDDTouch = cameraTransform.right * 0.07f
              }
              if (ddTouchpadPos.x > 0.5f + deadZone)
              {
                  normalizedDDTouch = cameraTransform.right * -0.08f
              }
              transform.localPosition += normalizedDDTouch;

Comment
Add comment · Show 5 · 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 Morice1999 · Sep 28, 2017 at 11:18 AM 0
Share

@Hellium

i just tested it after i build it and there it does not work so only in the editor do you know why?

Edit: i think camera doesnt rotate the empty object so anybody knows how to fix that ?

avatar image Hellium Morice1999 · Sep 28, 2017 at 01:07 PM 0
Share

Answer edited.

avatar image Morice1999 Hellium · Sep 29, 2017 at 06:51 AM 0
Share

@Hellium

That works but now i have another question:

when i look down i get slower i wiggle. i think because he want to go in the direction im looking so in the ground can i limit that on just forward ?

Ty anyways was great help Pls keep going on :)

Show more comments
avatar image
0

Answer by hlw · Sep 28, 2017 at 12:21 PM

If it only works in the editor, sometimes this kind of behaviour gets fixed by changing the script order in the project settings. Also, check if there is any float "is equal to/ x == y" (or something close to an is equal to) used to call the script that has to get called.

Comment
Add comment · Show 1 · 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 Morice1999 · Sep 28, 2017 at 12:36 PM 0
Share

changing the script order does not help and i dont understand what you wrote at last

Follow this Question

Answers Answers and Comments

157 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

Related Questions

Rotating GameObject Around Player With "Mouse Y" Position 2 Answers

Rotating objects to specific angle 3 Answers

Locking world rotation of child 1 Answer

Move towards VR Camera Orientation with Bluetooth Controller (Android) 0 Answers

Disable Windows Mixed Reality headset rotation/position tracking 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