void UTankTrack::ApplySidewaysForce()
{
	// Workout the required acceleration this frame to correct
	auto SlippageSpeed = FVector::DotProduct(GetRightVector(), GetComponentVelocity());
	auto DeltaTime = GetWorld()->GetDeltaSeconds();
	auto CorrectionAcceleration = -SlippageSpeed / DeltaTime * GetRightVector();

	// Calculate and apply sideways force ( F = ma )
	auto TankRoot = Cast<UStaticMeshComponent>(GetOwner()->GetRootComponent());
	auto CorrectionForce = (TankRoot->GetMass() * CorrectionAcceleration) / 2; // Two tracks

	TankRoot->AddForce(CorrectionForce);
}
Beispiel #2
0
void UTankTrack::ApplySidewaysForce()
{
	if (ensure(TankRoot))
	{
		FVector RightVector = GetRightVector();
		float DeltaTime = GetWorld()->GetDeltaSeconds();

		// Calculate the slippage speed
		float SlippageSpeed = FVector::DotProduct(RightVector, GetComponentVelocity());

		// Work-out the required acceleration this frame to correct
		FVector CorrectionAcceleration = -SlippageSpeed / DeltaTime * RightVector;

		// Calculate and apply sideways for ( F = m a)
		FVector CorrectionForce = (TankRoot->GetMass() * CorrectionAcceleration) / 2.f; // Two Tracks
		TankRoot->AddForce(CorrectionForce);
	}
}