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 glen-christie · Feb 24, 2018 at 07:05 AM · animationroot motionparameters

root motion problem. direction parameter set to 90 on start

Hi there, I am trying to set up a character with root motion animations, following the tutorials in Unity Animation Cookbook https://www.packtpub.com/game-development/unity-5x-animation-cookbook.

The animations are working correctly but the issue I have is that the Direction parameter goes to 90 as soon as I start the game. This causes the blend tree to play the Right Turn Walk animation before transitioning to idle when the character stops walking. The Direction parameter should be at 0 by default.

I think it is caused either by something wrong in my import settings on the rig or by the RootMotionSteering script that calculates the angle between the characters forward vector and the desiredMoveDirection vector. This value is used to set the Direction parameter in the Animator Controller, which is causing the problem.

Any help would be greatly appreciated. This is the RootMotionSteering script:

 using UnityEngine;
 using System.Collections;
 
 public class RootMotionSteering : MonoBehaviour {
 
     //This variable stores the reference to the camera placed in the scene
     //we will move the character relative to the camera
     public Transform cameraTransform;
 
     //This variable stores the reference to the Animator component of this game object
     Animator anim;
 
     //These variables store Horizontal and Vertical input values
     float hor = 0f;
     float ver = 0f;
 
     //This variable is used to calculate the speed value and set the Speed parameter in the Animator Controller
     //It is a public variable, because we want to use it in another script later
     [HideInInspector]
     public float speed = 0f;
 
     //This variable is used to calculate the direction we want to go to and set the Direction parameter in the Animator Controller
     //It is a public variable, because we want to use it in another script later
     [HideInInspector]
     public float direction = 0f;
 
     //This vector will point in the same direction as camera's forward, but will be completely horizontal (with the Y axis set to 0)
     //We are going to use it to move our character. 
     Vector3 cameraHorizontalForward;
 
     //This vector will be our desired move direction
     Vector3 desiredMoveDirection;
 
     void Start () {
 
         //We assign the Animator component to our anim variable when the game starts
         anim = GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
 
         //We set the hor and ver input values
         hor = Input.GetAxis("Horizontal");
         ver = Input.GetAxis("Vertical");
 
         //We calculate the horizontal camera forward direction, we use only horizontal axes
         cameraHorizontalForward = new Vector3(cameraTransform.forward.x, 0f, cameraTransform.forward.z).normalized;
 
         //We use player input stored in ver and hor variables along with horizontal camera forward vector and camera right vector to create
         //the desired move direction vector - this is a vector in world space in which we want to move our character
         desiredMoveDirection = ver * cameraHorizontalForward + hor * cameraTransform.right;
 
         //We calculate the angle between the forward axis of our character and the desired move vector. We multiply the angle by the sign (1 or -1) of the 
         //dot product of our desired move direction vector and our character's right axis. This dot will be greater than 0 if our desired move vector points towards
         //the right axis of our character, and it will be less than 0, when i points in the left direction. 
         direction = Vector3.Angle(transform.forward, desiredMoveDirection) * Mathf.Sign(Vector3.Dot(desiredMoveDirection, transform.right));
 
         //Speed is the magnitude of our desired move vector
         speed = desiredMoveDirection.magnitude;
 
         //We set the Direction and Speed parameters in our Animator Controller to make the character move. 
         anim.SetFloat("Direction", direction, 0.2f, Time.deltaTime);
         anim.SetFloat("Speed", speed, 0.2f, Time.deltaTime);
     }
 }




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 meat5000 ♦ · Feb 24, 2018 at 07:18 AM 0
Share

Check your setups of child objects and scripted movement/placement. Disable this script before starting to see if the problem occurs outside of the script.

avatar image glen-christie meat5000 ♦ · Feb 24, 2018 at 06:56 PM 0
Share

Thanks for your reply. When I disable the script the Direction parameter stays at 0.

Could you please explain the first part of your reply further?

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

200 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

Related Questions

The name animator does not exist in the current context... Help? 1 Answer

Physics with generic root motion 0 Answers

How to set/reset a parameter at the end of animation? 3 Answers

Player teleports when animation finishes 0 Answers

Root Motion in 2019.2 0 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