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 /
  • Help Room /
avatar image
0
Question by Salja · Dec 07, 2020 at 08:33 PM · movementanglecalculation

Worng SignedAngle

Hello everyone, I have a little problem and unfortunately I can't go on on my own. I'm currently working on a character controller and I want to calculate the angle while walking (-180, -90, 0, 90, 180) The whole thing works even if I run normally and am not in strafe mode, but as soon as I go into the strafe mode I get strange values (-0.3694153, -2.219208 -21.25256) Unfortunately, I don't get the values like without a strafe.

Because my English is not that good, I made another video https://youtu.be/MnsqcMp86zk

Here the code

 private void Update() {
             inputX = Input.GetAxisRaw("Horizontal");
             inputZ = Input.GetAxisRaw("Vertical");
 
             direction = new Vector3(inputX, 0, inputZ);
             direction.Normalize();
 
             // Check if we have movement input
             isMoving = direction != Vector3.zero;
 
             // If the movement is disabled return Vector.zero
             direction = playerInput.isMovementEnabled ? direction : Vector3.zero;
 
             inputMagnitude = direction.magnitude;
             inputMagnitude *= speedFactor;
 
             // Change MoveType if Player is in Stance to Strafe
             moveMode = stance == Stances.OneHandSword ? MoveMode.Strafe : MoveMode.Directional;
 
             if (playerInput.isRotationEnabled && isMoving) {
 
                 // Normal Movement none Strafe
                 if (moveMode == MoveMode.Directional) {
                     targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y;
                     angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothDamp);
 
                     transform.rotation = Quaternion.Euler(0f, angle, 0f);
                 }
 
                 // Strafe Movement
                 if (moveMode == MoveMode.Strafe) {
                     targetAngle = cameraTransform.eulerAngles.y;
                     angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothDamp);
 
                     transform.rotation = Quaternion.Euler(0f, angle, 0f);
                 }
             }
 
             Vector3 forwardA = cameraTransform.rotation * Vector3.forward;
             Vector3 forwardB = transform.rotation * Vector3.forward;
 
             // get a numeric angle for each vector, on the X-Z plane (relative to world forward)
             float angleA = Mathf.Atan2(forwardA.x, forwardA.z) * Mathf.Rad2Deg;
             float angleB = Mathf.Atan2(forwardB.x, forwardB.z) * Mathf.Rad2Deg;
 
             // get the signed difference in these angles
             float _signedAngle = Mathf.DeltaAngle(angleA, angleB);
 
             Debug.Log(_signedAngle);
 
             // Update Animator
             animator.SetFloat(HashHorizontal, direction.x, speedSmoothDamp, Time.deltaTime);
             animator.SetFloat(HashVertical, direction.z, speedSmoothDamp, Time.deltaTime);
             animator.SetFloat(HashInputMagnitude, inputMagnitude, speedSmoothDamp, Time.deltaTime);
             animator.SetInteger(HashStance, (int)stance);
             animator.SetBool(HashIsGrounded, isGrounded);
             animator.SetFloat(HashFalltime, lastFalltime);
             animator.SetBool(HashIsCrouching, isCrouching);
             animator.SetBool(HashIsDead, isDead);
 
             playerInput.UpdateInput();
 
             // Load ScriptableAbility on Update
             for (int i = 0; i < abilities.Count; i++) {
                 if (abilities[i].IsEnabled) {
                     abilities[i].OnCharacterUpdate();
                 }
             }
         }


alt text

screenshot-4.png (73.1 kB)
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

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

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

click and move script no working (as intended) 0 Answers

How to move object in 45/30/15 degree arch. 2 Answers

Rotation and Turn Giving Odd Angle 0 Answers

Calculate velocity x and y directions based on speed and angle 0 Answers

Acquiring a negative angle? 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