How to rotate my Pawn the direction it is going?

Hello friends,

Im trying to make a physics based sled game, where you just slide down hills.
The Problem is: I want the sled to automatically face the direction it is going to after some time.

Right now it is just rotating around the Z-axis while sliding downhill. I tried so many things over the past week and eventually read every article about it, but none of those seemed to work for me.

Tried it with Physics-Constraints, Mass Offset, Set (World, Relative) Rotation etc. …

Which way would be the best for my approach, so i can later still steer it and after steering it will automatically lerp to face the forward direction again?

Im new to UE, trying to learn it. I hope you can teach me something.
Thanks.

hi,
forward direction should be => (CurrentFramePosition - LastFramePosition).normalized
or you can just LookRotation(Velocity)

this is like a projectile following the trajection curve…

hope this helps you :slight_smile:

will make a little example in a few minutes… bed time here, after that i am back :wink:

cheers :vulcan_salute:

well, i would look at how they do it in CharacterMovement.
notice how they use FixedTurn at the bottom

I would experiment with the FixedTurn node and see if i can get what I’m looking for

void UCharacterMovementComponent::PhysicsRotation(float DeltaTime)
{
	if (!(bOrientRotationToMovement || bUseControllerDesiredRotation))
	{
		return;
	}

	if (!HasValidData() || (!CharacterOwner->Controller && !bRunPhysicsWithNoController))
	{
		return;
	}

	FRotator CurrentRotation = UpdatedComponent->GetComponentRotation(); // Normalized
	CurrentRotation.DiagnosticCheckNaN(TEXT("CharacterMovementComponent::PhysicsRotation(): CurrentRotation"));

	FRotator DeltaRot = GetDeltaRotation(DeltaTime);
	DeltaRot.DiagnosticCheckNaN(TEXT("CharacterMovementComponent::PhysicsRotation(): GetDeltaRotation"));

	FRotator DesiredRotation = CurrentRotation;
	if (bOrientRotationToMovement)
	{
		DesiredRotation = ComputeOrientToMovementRotation(CurrentRotation, DeltaTime, DeltaRot);
	}
	else if (CharacterOwner->Controller && bUseControllerDesiredRotation)
	{
		DesiredRotation = CharacterOwner->Controller->GetDesiredRotation();
	}
	else
	{
		return;
	}

	if (ShouldRemainVertical())
	{
		DesiredRotation.Pitch = 0.f;
		DesiredRotation.Yaw = FRotator::NormalizeAxis(DesiredRotation.Yaw);
		DesiredRotation.Roll = 0.f;
	}
	else
	{
		DesiredRotation.Normalize();
	}
	
	// Accumulate a desired new rotation.
	const float AngleTolerance = 1e-3f;

	if (!CurrentRotation.Equals(DesiredRotation, AngleTolerance))
	{
		// PITCH
		if (!FMath::IsNearlyEqual(CurrentRotation.Pitch, DesiredRotation.Pitch, AngleTolerance))
		{
			DesiredRotation.Pitch = FMath::FixedTurn(CurrentRotation.Pitch, DesiredRotation.Pitch, DeltaRot.Pitch);
		}

		// YAW
		if (!FMath::IsNearlyEqual(CurrentRotation.Yaw, DesiredRotation.Yaw, AngleTolerance))
		{
			DesiredRotation.Yaw = FMath::FixedTurn(CurrentRotation.Yaw, DesiredRotation.Yaw, DeltaRot.Yaw);
		}

		// ROLL
		if (!FMath::IsNearlyEqual(CurrentRotation.Roll, DesiredRotation.Roll, AngleTolerance))
		{
			DesiredRotation.Roll = FMath::FixedTurn(CurrentRotation.Roll, DesiredRotation.Roll, DeltaRot.Roll);
		}

		// Set the new rotation.
		DesiredRotation.DiagnosticCheckNaN(TEXT("CharacterMovementComponent::PhysicsRotation(): DesiredRotation"));
		MoveUpdatedComponent( FVector::ZeroVector, DesiredRotation, /*bSweep*/ false );
	}
}

Hey Guys thanks for your incredible quick answers!

Couldn´t reply as quick as i got corona and had a fever the last 2 days…

I somehow managed to solve the problem shortly after i wrote this question and it was how i imagined being sooo close all the time, yet so far…


It was just some little nodes/values that weren´t correct connected, but i guess that how it works. Either you get it 100% correct or it won´t work out.

In the end it´s so simple, but cost me a week to figure it out. Still learnt so much in this process and now i am extremely motivated to continue.

Thanks again guys!