Delta Time is implemented, but movement is still fps dependent.

Hello,

I recently started working on projectile physics from scratch and I learned about the concept of Delta Time, which makes physics calculations fps independent. I implemented Delta Time in my code, but the fps is still influencing the physics of my projectile.

Here is the code I wrote so far. I am pretty new to programming, so my code probably isn’t written most optimally, but everything works except when the fps changes, projectiles behave differently.

In Image 1, two projectiles are fired with an acceleration (TempAcc) of -1000000. The projectile closer to the player is fired at 50fps, and the one further is fired at 25fps.

Another example (Image 2) is projectile speed when fired at uncapped fps, which varies around 50 (± 2) fps. Acceleration is disabled (TempAcc is set to 0), and the projectile velocity is 100m/s. In the top-left corner, every second distance from the player is printed. As you can see, the distance varies every second because of the ever-changing fps, but it should constantly increment by 100 every second.

I have looked into physics substepping, but I think that will not fix my problem (I might be wrong). Other than that, I am clueless about what could be wrong and what I could do to fix this problem.

Thanks for the help in advance.

void ACPP_Projectile::CalculateMovement(float DeltaTime)
{
	FTransform ProjectileTransform = GetActorTransform();
	FVector ProjectileLocation = ProjectileTransform.GetLocation();

	SetActorLocation(MoveProjectile(ProjectileLocation, DeltaTime));
}

FVector ACPP_Projectile::MoveProjectile(FVector ProjectileLocation,float DeltaTime)
{
	FVector ProjectileFacing = GetActorForwardVector();

	if (Velocity == NULL) 
	{
		Velocity = ProjectileData->InitialSpeed * 100;
	}else if (Velocity < 0.01)
	{
		return ProjectileLocation;
	}

	
	//s = v0*t + 1/2 * a*t^2
	ProjectileLocation += Velocity * DeltaTime * ProjectileFacing + 1 / 2 *
    (TempAcc*100) * DeltaTime * ProjectileFacing;


	Velocity = CalculateVelocity(Velocity, DeltaTime);

	return ProjectileLocation;
}

float ACPP_Projectile::CalculateVelocity(float InitialVelocity, float DeltaTime)
{
	// v = v0 + a*t
	InitialVelocity = InitialVelocity + (TempAcc*100) * DeltaTime;
	
	return InitialVelocity;
}

the comment says to square the time value but it doesn’t look like you square it in the code.

You are right, that was an error. I’ve changed it, but it didn’t fix fps dependency.

Here is the solution if anybody has this problem in the future.