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 /
This question was closed Feb 11, 2018 at 11:46 PM by jakeomonk for the following reason:

Other

avatar image
0
Question by jakeomonk · Feb 20, 2014 at 05:00 PM · javascripteuleranglesground detectionfunction update

How Can I Reference A Range e.g. Between -90 & 90

I want to test whether my car is between a certain angle by using localEulerAngles but i dont know how to make it so that i can test for a range.

 function Update()
 {
     carPhysicsUpdate();
     if (Grounded && PlayerCar.localEulerAngles.z == //Between -90 & 90 degrees)
     {
         checkInput();
     }
     if (Input.GetKeyDown(KeyCode.Return))
     {
         if (Grounded)
         {
             PlayerCar.localEulerAngles.y = 0;
             PlayerCar.localEulerAngles.x = 0;
             PlayerCar.localEulerAngles.z = 0;
         }
     }
 }
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

  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Feb 20, 2014 at 05:23 PM

Let's start with the easy stuff...the answer to the explicit question you asked:

  var zAngle = PlayerCar.localEulerAngles.z;
  if (Grounded && ((zAngle >= 0 && zAngle <= 90) || (zAngle >= 270 && zAngle <= 360))) {

Note that localEulerAngles produces a value in the range of 0 to 360, so you have to check 0 - 90 and 270 - 360 independently.

The bad news is that this code may not work. It will likely work if the object is only being rotated on the 'z' axis. If you are doing arbitrary rotations on all axes, then you likely have to look to a more sophisticated solution. What solution will depend on the code you are using for the rotation of this object.

Note that lines 12 - 14 can be replaced by:

 PlayerCar.localEulerAngles = Vector3.zero;
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 jakeomonk · Feb 20, 2014 at 06:21 PM 0
Share

your code works but sadly my z angle of my car goes to $$anonymous$$us digits so when it is in that range my car doesn't drive, i really need a way of making it between 90 & -90 if you can

avatar image robertbu · Feb 20, 2014 at 06:49 PM 0
Share

If your localEulerAngles is producing negative angles, you can do:

 if (Grounded && (zAngle >= -90 && zAngle <= 90)) {
avatar image jakeomonk · Feb 20, 2014 at 07:54 PM 0
Share

okay so it appears that the angles i need are between (0 & 90) and (270 & 360) but sometimes it goes to $$anonymous$$us when on flat ground so how could i have this:

     if (Grounded && ((PlayerCar.localEulerAngles.z >= 0 && PlayerCar.localEulerAngles.z <= 90) || (PlayerCar.localEulerAngles.z >= 270 && PlayerCar.localEulerAngles.z <= 360)))

And then included $$anonymous$$us numbers aswell, so between (0 & -90)

avatar image robertbu · Feb 20, 2014 at 08:01 PM 0
Share

The easiest thing to do would be to normalize the result:

 var zAngle = PlayerCar.localEulerAngles.z;
 if (zAngle < 0.0)
     zAngle = zAngle + 360.0;
 if (Grounded && ((zAngle >= 0 && zAngle <= 90) || (zAngle >= 270 && zAngle <= 360))) {
avatar image jakeomonk · Feb 20, 2014 at 10:31 PM 0
Share

Thanks i managed to get it working using this:

 if (Grounded && ((PlayerCar.localEulerAngles.z >= 0 && PlayerCar.localEulerAngles.z <= 50) || (PlayerCar.localEulerAngles.z >= 310 && PlayerCar.localEulerAngles.z <= 360) || (PlayerCar.localEulerAngles.z <= 0)))

your suggestion glitched out thanks anyway.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Making a character rotate diagonal? 1 Answer

Temperature Script? 3 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