I had to do a little digging to see what was going on here.
At the point of Pickup, I did use GetNearestPickup(), but as we start to add new RangeFinder based classes (Conversants, Shops), you’ll notice that there’s a lot of duplicate code.
FineNearestTarget() is at the RangeFinder level, and regardless of the type of RangeFinder, it will select the nearest target and return true if that was possible, or false if there are no targets within the Targeter. It’s introduced in the entry Shopping Spree
We’re dealing with two different mechanics through this topic…
PlayerPickupState should be returning to PlayerFreelookState() when the Normalized time (GetNormalizedTime()) is greater than 0.8f
Now there is a bug I mentioned later in the Pickup lecture, in that it turns you DO have to specify the tag to get the GetNormalizedTime to work properly. So I changed the base GetNormalizedTime to take an optional parameter
protected float GetNormalizedTime(string tag = "Attack")
{
var currentInfo= stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
var nextInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);
if (stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag(tag))
{
return nextInfo.normalizedTime;
}
else if(!stateMachine.Animator.IsInTransition(0) && currentInfo.IsTag(tag))
{
return currentInfo.normalizedTime;
}
return 0;
}
This means you need to make sure that you call GetNormalizedTime with a parameter like “Pickup” and your Pickup animation state in the Animator needs a “Pickup” tag for the Normalized time to work properly.
For the shop… was the Dialogue window working correctly?