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
0
Question by DyrdaOrg · Dec 07, 2016 at 11:59 AM · c#vrif-statementseulerangles

What's wrong with my if states of eulerAxis.x in Update?

I have:

     public float moveAngleMin = 5.0f;
     public float moveAngleMax = 45.0f;
     public float runAngleMin = 355.0f;
     public float runAngleMax = 315.0f;

and in the Update function:

     void Update() {
         // Check rotation of head in X axis
         if (vrCamera.eulerAngles.x >= moveAngleMin && vrCamera.eulerAngles.x < moveAngleMax)
         {
             // Move forward
             moveForward = true;
             runForward = false;
         }
 
         if (vrCamera.eulerAngles.x <= runAngleMin && vrCamera.eulerAngles.x >= runAngleMax)
         {
             // Run forward
             moveForward = false;
             runForward = true;
         }
 
         else {
             // Stop moving
             moveForward = false;
             runForward = false;
         }
 
 
     }


The fun fact about above "if"s is that they work... for 2nd if - my character is able to run when I move my head up. When moving below 5 - nope he can't. But after changing the order of this "if"s - he can move but can't run - I tried else if and other things - can anybody help? I'll upvote of course good answer.

Thank you in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UnityCoach · Dec 07, 2016 at 12:26 PM

I may be mistaken, but I'm pretty sure you meant to write this :

 if (vrCamera.eulerAngles.x >= runAngleMin && vrCamera.eulerAngles.x <= runAngleMax)
 // instead of this
 if (vrCamera.eulerAngles.x <= runAngleMin && vrCamera.eulerAngles.x >= runAngleMax)
Comment
Add comment · Show 2 · 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 DyrdaOrg · Dec 07, 2016 at 01:08 PM 0
Share

Thank you for your quick reply but no - that part it's okay and it's working. The problem is that the only thing that's working is only 2nd part whatever I put there. Right now is that part about running. But when I move there statement about moving it's also working and run is not working. I'm pretty sure that my statements are defined correctly, bu maybe I should put them in one "if"? and later define speed by float?

The else statement is working as a charm and when I'm observing how VRCamera attached to the player is working it's correct (though it was some time I realised that in eulerAngles you don't have -45 but 315 ;) )

Sorry for the roughness of my draft but maybe it'll help better understand my problem and what I'm trying to achieve.

I'm using Unity 5.4 btw.

alt text

vrandroidxaxissmall.jpg (97.2 kB)
avatar image UnityCoach DyrdaOrg · Dec 07, 2016 at 01:42 PM 0
Share

Even thought it's not the problem, you may want to use Finite States to simplify things a little. Also, if they're mutually exclusive, you can use else if, to make sure one prevails on the other.

Like :

 public enum STATE {Idle, $$anonymous$$oving, Running};
 private STATE _state;
 private STATE State
 {
 get {return _state;}
 set
 {
 if (_state != value)
 {
 _state = value;
 }
 }
 }
 
 void Update() {
          // Check rotation of head in X axis
          if (vrCamera.eulerAngles.x >= moveAngle$$anonymous$$in && vrCamera.eulerAngles.x < moveAngle$$anonymous$$ax)
          {
              State = STAT$$anonymous$$$$anonymous$$oving;
          }
  
          else if (vrCamera.eulerAngles.x <= runAngle$$anonymous$$in && vrCamera.eulerAngles.x >= runAngle$$anonymous$$ax)
          {
              State = STAT$$anonymous$$Running;
          }
  
          else {
              State = STAT$$anonymous$$Idle;
          }
  
  
      }

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Look Rotation flipping object rotation after 180 degrees 1 Answer

Draw texture directly on Oculus screen 1 Answer

Enemy should follow the Player if he is in range, but how? 2 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