Hello friends, I’m working on a parkour system to integrate into my state machine, and I’ve been running into a problem I can’t seem to solve: Match Targeting
Last year I was following a parkour course and made it work after countless attempts. However, now I am stuck with Match Targeting all over again, and I have zero clue why (using what I learned last year into my project won’t work either. Back then, I was following a course and was doing it the normal way. Right now I’m using state machines)
Any help on why Match Targeting in the following code isn’t working would be highly appreciated:
using RPG.States.Player;
using UnityEngine;
public class PlayerLedgeHoldingState : PlayerBaseState
{
private readonly int IdleToBracedHangHash = Animator.StringToHash("IdleToBracedHang");
private readonly AvatarTarget targetBodyPart = AvatarTarget.RightHand;
private Vector3 ledgePosition;
private float animationStartTime;
private float animationEndTime;
private MatchTargetWeightMask weightMask;
public PlayerLedgeHoldingState(PlayerStateMachine stateMachine, Vector3 ledgePosition) : base(stateMachine)
{
this.ledgePosition = ledgePosition;
weightMask = new MatchTargetWeightMask(Vector3.one, 0);
}
public override void Enter()
{
Debug.Log($"Player has entered ledge holding state");
animationStartTime = 0.344f; // Start where the players' hand roughly touches the ledge
animationEndTime = 0.904f; // End just before the animation ends
stateMachine.Animator.CrossFadeInFixedTime(IdleToBracedHangHash, stateMachine.CrossFadeDuration);
}
public override void Tick(float deltaTime)
{
if (stateMachine.Animator.GetCurrentAnimatorStateInfo(0).normalizedTime < animationEndTime
&& stateMachine.Animator.GetCurrentAnimatorStateInfo(0).normalizedTime > animationStartTime)
{
MatchTargetToLedge();
}
}
public override void Exit()
{
Debug.Log($"Exiting ledge holding state");
}
private void MatchTargetToLedge()
{
stateMachine.Animator.MatchTarget(ledgePosition, Quaternion.identity, targetBodyPart,
weightMask, animationStartTime, animationEndTime);
}
}
Thank you in advance
I also went through the Unity documentation on Target Matching. No offence, but it was pointless
P.S: I have a force receiver script that replaces the player rigidbody, along with a character controller for the player. I tried shutting them down within the state, but to no avail, and now I am very clueless of what’s going on.
I also tried turning root motion for the animator during this state on, but that didn’t work either