Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 ThisIsMikita · Aug 16, 2017 at 10:28 AM · mecanimpathfindingroot motionalgorithmsteering

How to steer character by path using Root Motion?

I have a animated character in Unity3D and I've implemented A* pathfinding algorithm. So, I have a path that contains Vector3 nodes and I want to steer my character using Mecanim Root Motion. What is the best priactice to implement character steering by path and controlls him with such parameters as float Speed, AgularSpeed, Direction.

I've found this script implemented by Unity Technologies:

 using UnityEngine;
 using System.Collections;
 
 public class Locomotion
 {
     private Animator m_Animator = null;
     
     private int m_SpeedId = 0;
     private int m_AgularSpeedId = 0;
     private int m_DirectionId = 0;
 
     public float m_SpeedDampTime = 0.1f;
     public float m_AnguarSpeedDampTime = 0.25f;
     public float m_DirectionResponseTime = 0.2f;
     
     public Locomotion(Animator animator)
     {
         m_Animator = animator;
 
         m_SpeedId = Animator.StringToHash("Speed");
         m_AgularSpeedId = Animator.StringToHash("AngularSpeed");
         m_DirectionId = Animator.StringToHash("Direction");
     }
 
     public void Do(float speed, float direction)
     {
         AnimatorStateInfo state = m_Animator.GetCurrentAnimatorStateInfo(0);
 
         bool inTransition = m_Animator.IsInTransition(0);
         bool inIdle = state.IsName("Locomotion.Idle");
         bool inTurn = state.IsName("Locomotion.TurnOnSpot") || state.IsName("Locomotion.PlantNTurnLeft") || state.IsName("Locomotion.PlantNTurnRight");
         bool inWalkRun = state.IsName("Locomotion.WalkRun");
 
         float speedDampTime = inIdle ? 0 : m_SpeedDampTime;
         float angularSpeedDampTime = inWalkRun || inTransition ? m_AnguarSpeedDampTime : 0;
         float directionDampTime = inTurn || inTransition ? 1000000 : 0;
 
         float angularSpeed = direction / m_DirectionResponseTime;
         
         m_Animator.SetFloat(m_SpeedId, speed, speedDampTime, Time.deltaTime);
         m_Animator.SetFloat(m_AgularSpeedId, angularSpeed, angularSpeedDampTime, Time.deltaTime);
         m_Animator.SetFloat(m_DirectionId, direction, directionDampTime, Time.deltaTime);
     }
 }

I can controll character with something like this:

 protected void SetupAgentLocomotion()
 {
     if (agent.Arrive)
     {
         locomotion.Do(0, 0);
     }
     else
     {
         float speed = agent.desiredVelocity.magnitude;
 
         Vector3 velocity = Quaternion.Inverse(transform.rotation) * agent.desiredVelocity;
 
         float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;
 
         locomotion.Do(speed, angle);
     }
 }

But I don't know how to implement agent. I think I need something like NavMeshAgent with desiredVelocity.

PS. I can't use Unity's NavMesh because I have to use my own A* pathfinder. It's more acurate for me.

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

121 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

Related Questions

How to predict humanoid retargeting root y offset ? 0 Answers

Movement following the A* algorithm 0 Answers

Sliding issue with mecanim 0 Answers

Navmesh interfering with mecanim jump animation (root motion) 1 Answer

MatchTarget Rotating Character 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