using System.Collections; using System.Collections.Generic; using UnityEngine; using BITKit; using BITFALL.Entites; using KinematicCharacterController; using BITKit.StateMachine; using UnityEngine.InputSystem; using BITKit.Animations; using BITKit.Sensors; namespace BITFALL.Entites.KinematicMovementStates { [System.Serializable] public class ClimbBox : KinematicMovementState { public UnityAnimator animator; [SerializeReference, SubclassSelector] public References _vault; bool isEntied; Vector3 startPos; public override void OnStateEnter(IState old) { isEntied = false; motor.ForceUnground(); motor.SetCapsuleCollisionsActivation(false); motor.SetGroundSolvingActivation(false); motor.SetMovementCollisionsSolvingActivation(false); controller.groundState.shouldBe = true; controller.groundState.Release(); startPos = motor.TransientPosition; } public override void OnStateExit(IState old, IState newState) { base.OnStateExit(old, newState); motor.SetCapsuleCollisionsActivation(true); motor.SetGroundSolvingActivation(true); motor.SetMovementCollisionsSolvingActivation(true); } public override void BeforeCharacterUpdate(float deltaTime) { if (animator[0].fullStateName != _vault) { controller.entity.Invoke(Constant.Animation.Play, _vault.Get()); } //if (animator.animator.IsInTransition(0) is false) /* animator.animator.MatchTarget( controller.matchTargetPosition, motor.TransientRotation, AvatarTarget.LeftFoot, new MatchTargetWeightMask(Vector3.one, 1) , 0.4f, 0.6f); */ } public override void AfterCharacterUpdate(float deltaTime) { base.AfterCharacterUpdate(deltaTime); //if (animator.animator.IsInTransition(0) is false) { if (animator[0].fullStateName == _vault) { if (isEntied && animator[0].currentState.normalizedTime > 1f) { TransitionState(); } isEntied = true; } } controller.jumpState.shouldBe=false; } public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime) { //if (animator.animator.IsInTransition(0) is false) // currentVelocity = animator.GetRootVelocity(); //currentVelocity=animator.animator.velocity; if (animator[0].fullStateName == _vault) if (animator.animator.IsInTransition(0) is false) { var normalizedTime = animator[0].currentState.normalizedTime; var direction = Vector3.Lerp(startPos, controller.matchTargetPosition, normalizedTime); var linear = currentVelocity = (direction - motor.TransientPosition) / deltaTime; var rootVelocity = animator.GetRootVelocity(); currentVelocity = Vector3 .Lerp(rootVelocity, linear, normalizedTime); } } } }