Weird rotational behavior on custom character movement.

I switched my rotation functions from using rotators to quats, but it didn’t help much. It actually seems a bit worse.

After switching to quats, it goes all weebly wobbly. That is the only way I know how to describe it.

Anyone see any glaring faults in my code that would cause this?


FQuat UAdvancedMovementComponent::TurnUpright(FVector UpVector, FQuat InRot, float DeltaTime)
{
	FVector UP = UpVector;

	if (UpdatedComponent != NULL)
	{
		FQuat NewRot = FQuat::FindBetweenVectors(InRot.GetAxisZ(), UP);
		NewRot = InRot * NewRot;

		if (true)
		{
			return NewRot;
		}
		else
		{
			return InRot;
		}

	}
	else
	{
		return InRot;
	}
}


FQuat UAdvancedMovementComponent::TurnFromAim(float DeltaTime, FQuat InRot, bool UseYaw, bool UsePitch, bool UseRoll)
{
	FVector YawAxis = InRot.GetUpVector();
	FVector PitchAxis = InRot.GetRightVector();
	FVector RollAxis = InRot.GetForwardVector();

	FQuat Rot = InRot;

	if (UseYaw)
	{
		FVector Axis = YawAxis;
		float AimAngle = Aim.Z;
		float Angle;

		if (AimAngle > TurnSpeed * DeltaTime)
		{
			Angle = TurnSpeed * DeltaTime;
			AimAngle -= TurnSpeed * DeltaTime;
		}
		else if (AimAngle < TurnSpeed * DeltaTime * -1)
		{
			Angle = -1 * TurnSpeed * DeltaTime;
			AimAngle += TurnSpeed * DeltaTime;
		}
		else
		{
			Angle = AimAngle;
			AimAngle = 0;
		}

		Aim.Z = AimAngle;
		float Rad = FMath::DegreesToRadians(Angle);
		FQuat SubRot = FQuat(Axis, Rad);
		Rot = Rot * SubRot;
	}

	if (UsePitch)
	{
		FVector Axis = PitchAxis;
		float AimAngle = Aim.Y;
		float Angle;

		if (AimAngle > TurnSpeed * DeltaTime)
		{
			Angle = TurnSpeed * DeltaTime;
			AimAngle -= TurnSpeed * DeltaTime;
		}
		else if (AimAngle < TurnSpeed * DeltaTime * -1)
		{
			Angle = -1 * TurnSpeed * DeltaTime;
			AimAngle += TurnSpeed * DeltaTime;
		}
		else
		{
			Angle = AimAngle;
			AimAngle = 0;
		}

		Aim.Y = AimAngle;
		float Rad = FMath::DegreesToRadians(Angle);
		FQuat SubRot = FQuat(Axis, Rad);
		Rot = Rot * SubRot;
	}

	if (UseRoll)
	{
		FVector Axis = RollAxis;
		float AimAngle = Aim.X;
		float Angle;

		if (AimAngle > TurnSpeed * DeltaTime)
		{
			Angle = TurnSpeed * DeltaTime;
			AimAngle -= TurnSpeed * DeltaTime;
		}
		else if (AimAngle < TurnSpeed * DeltaTime * -1)
		{
			Angle = -1 * TurnSpeed * DeltaTime;
			AimAngle += TurnSpeed * DeltaTime;
		}
		else
		{
			Angle = AimAngle;
			AimAngle = 0;
		}

		Aim.X = AimAngle;
		float Rad = FMath::DegreesToRadians(Angle);
		FQuat SubRot = FQuat(Axis, Rad);
		Rot = Rot * SubRot;
	}

	return Rot;
}


Silly me. I was multiplying my quats backwards. I guess that is what happens when you’ve been using blueprints for too long.