How to GetDeltaSeconds in 4.19?

I cannot GetDeltaSeconds with the new standard. Including the Actor and World headers does nothing. The component has no idea what “GetWorld” and “GetDeltaSeconds” is.

My Code for TankTrack.cpp

#include "TankTrack.h"

UTankTrack::UTankTrack()
{
	PrimaryComponentTick.bCanEverTick = false;
}

void UTankTrack::BeginPlay()
{
	Super::BeginPlay();
	OnComponentHit.AddDynamic(this, &UTankTrack::OnHit);
}

void UTankTrack::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit) 
{
	//Drive the tracks
	ApplySidewaysForce();
}

void UTankTrack::SetThrottle(float Throttle)
{
	//TODO Clamp actual throttle value so the player can't overdrive the tank.
	auto ForceApplied = GetForwardVector() * Throttle * TrackMaxDrivingForce;
	auto ForceLocation = GetComponentLocation();
	auto TankRoot = Cast<UPrimitiveComponent>(GetOwner()->GetRootComponent());
	TankRoot->AddForceAtLocation(ForceApplied, ForceLocation);
}

void ApplySidewaysForce()
{
	//Calculate slippage speed.
	auto SlippageSpeed = FVector::DotProduct(GetRightVector(), GetComponentVelocity());
	auto DeltaTime = GetWorld()->GetDeltaSeconds();
	//Work out the required acceleration this frame to correct.
	auto CorrectionAcceleration = -SlippageSpeed / DeltaTime * GetRightVector();
	//Calculate and apply sideways force.
	auto TankRoot = Cast<UStaticMeshComponent>(GetOwner()->GetRootComponent());
	auto CorrectionForce = (TankRoot->GetMass() * CorrectionAcceleration) / 2; // Divided by two because there are two tracks applying the corrective force.

	TankRoot->AddForce(CorrectionForce);
}

Idiocy on my end: Forgot to add the function to the header and give the function a class. No extra includes needed.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms