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 Tiernan98 · Dec 21, 2018 at 07:59 PM · animationtransformanimatorcharacter controller

Root motion in child not moving with parent

Hi!

So I have set a moving platform like so:

 public class MovingPlatform : MonoBehaviour
 {
     public void AttachTransform(Transform transform)
     {
         transform.parent = this.transform;
     }
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.CompareTag("Player"))
         {
             other.transform.parent = transform;
         }
     }
 
     private void OnTriggerExit(Collider other)
     {
         PlayerController player = other.GetComponent<PlayerController>();
 
         if (other.CompareTag("Player") && !player.StateMachine.IsInState<Locomotion>())
         {
             other.transform.parent = null;
         }
     }
 
     private void OnTriggerStay(Collider other)
     {
         if (other.CompareTag("Player"))
         {
             PlayerController player = other.GetComponent<PlayerController>();
 
             if (player.StateMachine.IsInState<Jumping>())
                 OnTriggerExit(other);
         }
     }
 }

The extra AttachTransform function is just for when the character is going to grab the ledge so it can be attached earlier and align properly (auto-grab system).

When the character is hanging from this ledge (with root motion enabled), they are a child for the object holding this script, and the character correctly moves up and down with the platform.

The problem comes whenever I press space to climb-up. The animation plays at the point where I pressed it and the character doesn't continue to move up with the ledge, so the character ends up standing up in thin air and falls. This issue also occurs when shimmying left or right. I have checked that the character is definitely a child of the platform when climbing up, so that is not the issue.

Climbing up itself is never an issue on stable non-moving platforms. The code looks like this:

 private void ClimbUp(PlayerController player)
     {
         player.camController.State = CameraState.Grounded;
 
         player.Anim.SetFloat("Speed", 0f);
         player.Anim.SetFloat("TargetSpeed", 0f);
 
         if (Input.GetButton("Sprint"))
             player.Anim.SetTrigger("Handstand");
         else
             player.Anim.SetTrigger("ClimbUp");
 
         isClimbingUp = true;
     }

And in the state update method;

 if (isClimbingUp)
         {
             if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle"))
             {
                 player.StateMachine.GoToState<Locomotion>();
             }
             
             return;
         }

Does using a root motion animation stop the player moving with the ledge? Its very unusual because the player did successfully climb up on a small number of tries, but I didn't change anything in the code that would have fixed it. It was like by chance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JonPQ · Dec 21, 2018 at 10:50 PM

at a guess.... you probably want to make sure that the animation on the character is not animation the root's world position... and only animating children of the root... say from a helper bone, or pelvis and onward from there.

You might also want to turn off all of your collision code once character is grabbing ledge and parented to the ledge.... no need for collisions, and they might just make some strange code execute. Turn the collisions back on after the climbing sequence has finished.

Comment
Add comment · Show 2 · Share
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 Tiernan98 · Dec 21, 2018 at 10:58 PM 0
Share

Thanks for the answer.

Collisions are disabled during climbing. So perhaps your suggestion about it animating the world position is correct. I think that it is the world position changing. How would I work around that if I cannot edit the animations?

EDIT: Added some code that literally adds the change of position of the platform to the player's position if root motion is being applied. Its something. $$anonymous$$akes it look worse when standing on the platform I think because no Y root motion is applied perhaps? I will try just applied the change in position of the platform without the object being a child.

EDIT 2: I tried what I said above and that seems to have solved my issue. The only issue I have is that sometimes it looks like player is trying to catch up with the platform. I can probably figure it out myself, but if you have any immediate idea that comes to $$anonymous$$e, feel free to tell. :)

avatar image JonPQ Tiernan98 · Dec 26, 2018 at 04:17 PM 0
Share

workarounds ...hrmmm... yes, as you are doing... apply opposite position translate to what is going on in the root motion. maybe a better option would be to parent your character with another empty gameObject above it. maybe all the time, or maybe only when its grabbing the ledge. the parent object could maybe be at the grab point on the ledge, with an offset to your child's root... it "might" avoid the root motion affecting global position... but not sure

avatar image
0

Answer by golaod · Jun 09, 2021 at 08:00 PM

It's an old topic, but I just had the same issue. I moved my old project to new unity and new render pipeline system and same script, same player and same platform stopped working.


After checking all the topics with rigidbody, OnTriggerStay, position correction and so on, I found out that there is 'auto sync transforms' option which was not enabled in my new project. When I reenabled it, things went back to normal. (Edit -> Project Settings -> Physics (or Physics 2d) -> Auto Sync Transforms

Comment
Add comment · Share
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

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

276 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

Related Questions

Rig object offsets during animations 0 Answers

Why is my Character staying in Air Idle rather than Grounded Idle? 0 Answers

Play animation as the value changes from 0 to 1 with changing GameObject's position in unity 0 Answers

Why Editor throws Null Reference Exception when changing a transforms position while animation clips rec mode? 0 Answers

Transformation/Rotation of completed animation to fit on scene 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