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 /
  • Help Room /
avatar image
0
Question by sral123 · Jun 12, 2018 at 06:01 AM · 3dquaternioneulerangles

Reading Quaternion.eulerAngles.y smaller 45 and greater 315 does not work

Reading Quaternion.eulerAngles.y smaller 45 and greater 315 does not work

Hi, I have got a player that always faces the mouse and can move in all directions (Top Down View, 3D). This way you can for example move bakcwards but still look in any direction. To animate the player correctly, animations should be called depending on Input and on the Y-axis rotation of the player (see script). For that I have divided the the 360 degrees in 4 parts. While the last 3 if statements work just fine, the first one, which should read y-angles smaller 45 and greater 315 does not work. (the Quaternions are saved in the static variable PlayerPosition.playerRot). I tried different values and bools and was thinking about trying the mouseposition input, but there angles would be needed too.

Does anyone have an idea why? Any help and suggestions are highly appreciated

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
  
 public class PlayerWhiteAnimation : MonoBehaviour
 {
    
     Animator anim;
  
     void Start ()
     {
        
         anim = GetComponent<Animator>();
     }
  
  
     void Update ()
     {
         // this first if statement does not work...
             if (PlayerPosition.playerRot.eulerAngles.y >= 315 && PlayerPosition.playerRot.eulerAngles.y <= 45)
             {
                 if (Input.GetKey(KeyCode.A)) anim.SetTrigger("MovesLeft");
                 if (Input.GetKey(KeyCode.D)) anim.SetTrigger("MovesRight");
                 if (Input.GetKey(KeyCode.S)) anim.SetTrigger("MovesBack");
                 if (Input.GetKey(KeyCode.W)) anim.SetTrigger("MovesForw");
             }
             else
             if (PlayerPosition.playerRot.eulerAngles.y >= 45 && PlayerPosition.playerRot.eulerAngles.y <= 135)
             {
          
  
                     if (Input.GetKey(KeyCode.W)) anim.SetTrigger("MovesLeft");
                     if (Input.GetKey(KeyCode.S)) anim.SetTrigger("MovesRight");
                     if (Input.GetKey(KeyCode.D)) anim.SetTrigger("MovesForw");
                     if (Input.GetKey(KeyCode.A)) anim.SetTrigger("MovesBack");
             }
             else
             if (PlayerPosition.playerRot.eulerAngles.y >= 135 && PlayerPosition.playerRot.eulerAngles.y <= 225)
             {
          
                 if (Input.GetKey(KeyCode.W)) anim.SetTrigger("MovesBack");
                 if (Input.GetKey(KeyCode.S)) anim.SetTrigger("MovesForw");
                 if (Input.GetKey(KeyCode.D)) anim.SetTrigger("MovesLeft");
                 if (Input.GetKey(KeyCode.A)) anim.SetTrigger("MovesRight");
             }
             else
             if (PlayerPosition.playerRot.eulerAngles.y <= 315 && PlayerPosition.playerRot.eulerAngles.y >= 225)
             {
          
                 if (Input.GetKey(KeyCode.W)) anim.SetTrigger("MovesRight");
                 if (Input.GetKey(KeyCode.S)) anim.SetTrigger("MovesLeft");
                 if (Input.GetKey(KeyCode.D)) anim.SetTrigger("MovesBack");
                 if (Input.GetKey(KeyCode.A)) anim.SetTrigger("MovesForw");
             }
          
      
  
     }
 }
  
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 sral123 · Jun 12, 2018 at 06:01 AM 0
Share

sloved it, and sorry I found the solution in the forum here https://answers.unity.com/questions/467139/identify-range-of-rotation-eulerangles-not-working.html

in this case, ins$$anonymous$$d of using Quaternions it is better to use Vector3.Angle(transform.foward, Vector3.forward) < 45. When looking north, the <45 gives the range between 315 and 45.<90 would give 270 to 90. Also, there was no need to store the Quaternions in a static variable, I could have just refered to the parent. See working script below

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerBlackAnimation : $$anonymous$$onoBehaviour
 {
 
     Animator anim;
 
     void Start()
     {
 
         anim = GetComponent<Animator>();
     }
 
 
     void Update()
     {
         
             if (Vector3.Angle(transform.parent.forward, Vector3.forward)< 45)
             {
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) anim.SetTrigger("$$anonymous$$ovesLeftBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) anim.SetTrigger("$$anonymous$$ovesRightBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S)) anim.SetTrigger("$$anonymous$$ovesBackBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) anim.SetTrigger("$$anonymous$$ovesForwBl");
                        
             }
             else
         
             if(Vector3.Angle(transform.parent.forward, Vector3.right) < 45)
             {
 
 
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) anim.SetTrigger("$$anonymous$$ovesLeftBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S)) anim.SetTrigger("$$anonymous$$ovesRightBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) anim.SetTrigger("$$anonymous$$ovesForwBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) anim.SetTrigger("$$anonymous$$ovesBackBl");
             }
             else
        
             if (Vector3.Angle(transform.parent.forward, -Vector3.forward) < 45)
             {
 
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) anim.SetTrigger("$$anonymous$$ovesBackBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S)) anim.SetTrigger("$$anonymous$$ovesForwBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) anim.SetTrigger("$$anonymous$$ovesLeftBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) anim.SetTrigger("$$anonymous$$ovesRightBl");
             }
             else
         
             if (Vector3.Angle(transform.parent.forward, -Vector3.right) < 45)
             {
 
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) anim.SetTrigger("$$anonymous$$ovesRightBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S)) anim.SetTrigger("$$anonymous$$ovesLeftBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) anim.SetTrigger("$$anonymous$$ovesBackBl");
                 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) anim.SetTrigger("$$anonymous$$ovesForwBl");
             }
 
 
 
     }
 }

 
avatar image sral123 · Jun 12, 2018 at 06:15 AM 0
Share

Not sure though how to get an diagonal angle between for example 300 and 330.

Any advice?

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.

Follow this Question

Answers Answers and Comments

153 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

Related Questions

Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer

Any simple ways of keeping track of simple rotation? 2 Answers

Help With Quaternion.LookRotation 1 Answer

Rotate clockwise/counterclockwise using Quaternion.Slerp() 0 Answers

Need Help With Having Enemy Arms Pointed at Player 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