Search Unity

Discussion Need help with Rigidbody isKinematic on objects with Animator attached

Discussion in 'Physics' started by denya56, Feb 6, 2024.

  1. denya56

    denya56

    Joined:
    Apr 19, 2022
    Posts:
    2
    Hello there!
    I I'm doing a scene in Unity where player can use a fire extinguisher to extinguish fire in front of it. I got a 3d model of the fire extinguisher. It consists of several parts like seal, handle, bolt which are child objects of "Extinguisher".

    The functionality i want to implement is after clicking on a seal, animation of unlocking the extinguisher should play after which the seal and the bolt should fall to the ground. The animation is basically moving the seal and the bolt to the side of the extinguisher. Animator is attached to the "Extinguisher" object.

    I created an animation clip and attached and Pointer Click Event Trigger to the seal which plays the animation.
    This is how my Animator looks like:
    upload_2024-2-6_18-32-20.png
    ExtinguisherUnlock state has Behaviour script attached:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class UnlockBehaviour : StateMachineBehaviour
    6. {
    7.     private Rigidbody _rbSeal;
    8.     private Rigidbody _rbBolt;
    9.  
    10.     public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    11.     {
    12.         _rbSeal = animator.transform.Find("Seal").GetComponent<Rigidbody>();
    13.         _rbBolt = animator.transform.Find("Bolt").GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    17.     {
    18.         _rbSeal.isKinematic = false;
    19.         _rbBolt.isKinematic = false;
    20.         _rbSeal.WakeUp();
    21.         _rbBolt.WakeUp();
    22.  
    23.         animator.SetBool("isUnlocked", true);
    24.     }  
    25. }
    26.  
    So I change isKinamatic to false for both seal and bolt. After checking in the inspector, isKinematic is set to false but objects don't fall.

    I can see in the inspector that the speed and velocity of the object is changing but no effect on the position.

    I tried switching on/off Write defaults in every animator state and it didn't help. I setting imported model scaling from 100 to 1 but still no result.
    Removing seal from being a child object as well as using Animation Event to set isKinematic to false also didn't help.
    Freeze position is also unchecked, as well as "Static" next to Layer selector.
    upload_2024-2-6_18-41-9.png
    (Tried changing drag and angular drag as well)
    Would be glad if anyone could help, can provide more info/screenshots if needed :)
     
  2. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    275
    are you setting the position of the bolt anywhere in the idle animation after you turn off kinematic?
     
  3. denya56

    denya56

    Joined:
    Apr 19, 2022
    Posts:
    2
    Idle is just an empty state