Turn Left and Turn Right Animations with BlendSpace

Hello,
i have tried to make a BlendSpace. The goal is, that when the Ai from my Character goes Right, then the Blendspace or the BP should play the Turn Right Animation. But i won’t work.

Here are my Setting from the BlendSpace:

Here are my Setting from the AnimBP:
8e3cbe40abdfd0a88d867bebfeba66642993ec77.jpeg

I get a Error in the BP but i don’t understand this Error-Message.

Can someone please help me?
Kind regards,
halobungie

Hello,
in this video you can see the Problem:- YouTube
There aren’t smooth Turn’s. But i have some good Turn-Left and Turn-Right Animations.

Did someone know the solution how i can Play this (Turn-Left and Turn-Right)-Animations if the Spider goes left or Right?

Kind regards,
halobungie

On the character be sure to disable Use Controller Rotation Yaw. This is a property of ACharacter in C++ and in blueprint can be found by clicking the character itself.

Also not sure why you’re trying to cast to the anim blueprint there if you’re already in the anim blueprint. Hard to see but it looks like you’re trying to cast Get Pawn Owner to the Anim Blueprint which would in fact always fail. You already are in the anim blueprint and have a reference to self. The pawn owner is the ACharacter instance driving the blueprint.

I did some things in C++ for my character and it includes aim offsets as well so they can aim around while standing without triggering a turn in place animation. This should be doable in blueprint as well.
It works pretty well but I’m still working on smoothing it out a bit more.

It works for a human controlled player and I think would work for an AI player as well if AI also calls FaceRotation;

In the .h file



        virtual void FaceRotation(FRotator NewControlRotation, float DeltaTime) override;

        /** get aim offsets */
	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Animation)
	FRotator GetAimOffsets() const;

        UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Animation)
	float GetLeftMaxAimYawOffset() const;

	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Animation)
	float GetRightMaxAimYawOffset() const;

	UPROPERTY(BlueprintReadWrite, Category = Animation)
	float DesiredYaw;

        //This is the value that is read in the animation blueprint to drive the turn in place blendspace
        //Still working on tweaking this, I currently have to multiply this by 10 in the anim blueprint to have it show up and it's not quite 100% right yet
	UPROPERTY(BlueprintReadWrite, Category = Animation)
	float YawSpeed;


In the .cpp file



float AWRCharacter::GetLeftMaxAimYawOffset_Implementation() const
{
	//TODO: get this from the weapon.  Some weapons may want to limit this so when you look down your gun isn't clipping through your legs.
	return 45.f;                 //My aim offsets are designed for 90 degrees but I limit it to 45 since the character is usually positioned very awkwardly and it's only there for the information
        //just use a value of 0 or don't even implement this function at all for characters like your spider which has no aim offsets
}

float AWRCharacter::GetRightMaxAimYawOffset_Implementation() const
{
	//TODO: get this from the weapon.  Some weapons may want to limit this so when you look down your gun isn't clipping through your legs.
	return 45.f;                 //My aim offsets are designed for 90 degrees but I limit it to 45 since the character is usually positioned very awkwardly and it's only there for the information
        //just use a value of 0 or don't even implement this function at all for characters like your spider which has no aim offsets
}

//This was taken straight from the First Person Shooter example
FRotator AWRCharacter::GetAimOffsets_Implementation() const
{
	const FVector AimDirWS = GetControlRotation().Vector();
	const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS);
	const FRotator AimRotLS = AimDirLS.Rotation();

	return AimRotLS;
}

//This is an overridden function
void AWRCharacter::FaceRotation(FRotator NewControlRotation, float DeltaTime)
{
	//if not standing still, always make yaw equal rotation
	bool bStandingOnGround = false;
	float InterpSpeed = 3.f;
	float LastYaw = GetActorRotation().Yaw;
	NewControlRotation.Yaw = FMath::UnwindDegrees(NewControlRotation.Yaw);

	FRotator CurrentRot(GetActorRotation());

	if (GetCharacterMovement()->IsMovingOnGround())
	{
		FVector2D HorzVelocity(GetVelocity());
		if (HorzVelocity.SizeSquared() == 0.f)
		{
			bStandingOnGround = true;

			float CurrentYawOffset = GetAimOffsets().Yaw;

			//make character turn in place if twisted too far
			if (CurrentYawOffset > GetRightMaxAimYawOffset())
			{
				CurrentRot.Yaw = FMath::UnwindDegrees(CurrentRot.Yaw + CurrentYawOffset - GetRightMaxAimYawOffset());
				DesiredYaw = NewControlRotation.Yaw;
			}
			else if(-CurrentYawOffset > GetLeftMaxAimYawOffset())
			{
				CurrentRot.Yaw = FMath::UnwindDegrees(CurrentRot.Yaw + CurrentYawOffset + GetLeftMaxAimYawOffset());
				DesiredYaw = NewControlRotation.Yaw;
			}
		}
	}
	
	if (!bStandingOnGround)
	{
		DesiredYaw = NewControlRotation.Yaw;
		InterpSpeed = 8.f;
	}

	FRotator DesiredRot(CurrentRot);
	DesiredRot.Yaw = DesiredYaw;

	if (!FMath::IsNearlyEqual(LastYaw, DesiredYaw, 2.0f))
	{
		SetActorRotation(FMath::RInterpTo(CurrentRot, DesiredRot, DeltaTime, InterpSpeed));

		//first find shortest delta angle
		YawSpeed = FMath::RadiansToDegrees(FMath::FindDeltaAngle(FMath::DegreesToRadians(LastYaw), FMath::DegreesToRadians(GetActorRotation().Yaw)));
	}
	else
	{
		SetActorRotation(DesiredRot);
		YawSpeed = 0.f;
	}
}