Having problem in unity character controller animation

Hi everyone,
I am new to unity and I created basic movements of character with character controller (Run,walk,jump) but when I am trying to move controller for climbing high obstacles (Like hanging on ledge ) ,with animation clips curves , a controller.center=(new Vector3(0,animator.GetFloat(“ColliderY”),0.0f)); Its not working, values of controller in inspector is changing but not moving.

I also tried controller.Move() but it is jumping higher and animation is happening above the obstacle xD. And also I am using Starter Assets-Third Person Controller Root Animation worked somewhat but I read somewhere that it’s not good for game mechanics.

Here is my script-

using UnityEngine;
using StarterAssets;
using UnityEngine.InputSystem;
public class ClimbObjects : MonoBehaviour
{
    StarterAssetsInputs _input;
    Animator animator;
    CharacterController controller;
    PlayerInput input;
    int climb;
    
   
    private void Awake() {
     
        controller=GetComponent<CharacterController>();
        animator=GetComponent<Animator>();
        _input=GetComponent<StarterAssetsInputs>();
        climb=Animator.StringToHash("ClimbUp");
    }

 
 private void OnTriggerStay(Collider other) {
        if(other.gameObject.tag=="Climb"){
        
            
         
            if((Vector3.Dot(Vector3.forward, transform.InverseTransformPoint(other.transform.position)) > 0)&&_input.jump){
                 if (!animator.GetCurrentAnimatorStateInfo(1).IsName("ClimbUp") )
                {
                        if(!animator.IsInTransition(1))
                            {
                                if(animator.GetFloat("ColliderY")==0){
                                      controller.center=(new Vector3(0,0.93f,0.0f));
                                }
                                else{
                                 controller.center=(new Vector3(0,animator.GetFloat("ColliderY"),0.0f));
                            
                                 Debug.Log(animator.GetFloat("ColliderY"));
                             }
                }     
                     
                    
                     animator.SetTrigger("Climb");
          }
      }
    }
 }

    



private void OnTriggerExit(Collider other) {
        if(other.gameObject.tag=="Climb"){
            animator.ResetTrigger("Climb");
        }
    }
}

This topic was automatically closed after 2 days. New replies are no longer allowed.

Privacy & Terms