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 NJ_Sol · Jul 25, 2019 at 08:57 PM · animationanimator controllerspeeddirectionnavigation

Passing speed and direction to an Animator Controller

Hi everyone!
I'm new to Unity (especially to its coding side) so I've encountered a problem and I haven't been able to find the solution for days. I have a few Humanoid characters in my scene. Position of each of them is controlled by Simple Waypoint System and NavMeshAgent script. Speed and direction for animation blendtrees of every Animator Controller are passed by a Simple Waypoint System script called "MoveAnimator". Most of the time it works fine, but it overrides Root Motion in Animator. So whenever my character, for example, needs to sit down, he won't turn around and sit, he will just move his legs in place and will sit down on the wrong side of the chair. So I am wondering: is there any way to modify this script so it doesn't override the root motion? And if there's not: is there any other way of passing speed and direction of an object to its Animator Controller?

P.S. here's the MoveAnimator Script and the list of all the object's components: alt text

 /*  This file is part of the "Simple Waypoint System" project by Rebound Games.
  *  You are only allowed to use these resources if you've bought them from the Unity Asset Store.
  *     You shall not license, sublicense, sell, resell, transfer, assign, distribute or
  *     otherwise make available to any third party the Service or the Content. */
 
 using UnityEngine;
 using DG.Tweening;
 using UnityEngine.AI;
 
 namespace SWS
 {
 
     public class MoveAnimator : MonoBehaviour
     {
         private splineMove sMove;
         private NavMeshAgent nAgent;
         private Animator animator;
         private float lastRotY;
 
 
         void Start()
         {
             animator = GetComponentInChildren<Animator>();
 
             sMove = GetComponent<splineMove>();
             if (!sMove)
                 nAgent = GetComponent<NavMeshAgent>();
 
         }
 
 
         void OnAnimatorMove()
         {
             //init variables
             float speed = 0f;
             float angle = 0f;
 
             if (sMove)
             {
                 speed = sMove.tween == null || !sMove.tween.IsPlaying() ? 0f : sMove.speed;
                 angle = (transform.eulerAngles.y - lastRotY) * 10;
                 lastRotY = transform.eulerAngles.y;
             }
             else
             {
                 speed = nAgent.velocity.magnitude;
                 Vector3 velocity = Quaternion.Inverse(transform.rotation) * nAgent.desiredVelocity;
                 angle = Mathf.Atan2(velocity.x, velocity.z) * 2.0f / 3.14159f;
             }
 
             animator.SetFloat("Speed", speed);
             animator.SetFloat("Direction", angle, 0.15f, Time.deltaTime);
         }
     }
 }

снимок.png (28.2 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

Need help playing animation in reverse 1 Answer

Animator for Props 0 Answers

[Solvedf]Animator is not playing an AnimatorController 2 Answers

Velocity not changing value in Blend Tree 0 Answers

Animation stuck if i hold the trigger Button 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