Be the first to post for 'Simulating Rolling Resistance'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I am getting a weird effect with my vehicle shooting off into a wall or something after implementing the GetRollingResistance function. The screen goes black after I hit any of the movement keys and then I can no longer move at all. I hit escape to go back into the editor and it looks like I’m inside one of the walls. I have to go to the World Outliner tab and double click one of the objects in order to re-center my view in the level. All my variables and code are set up exactly as the lecture project changes. I am using UE4 4.23 editor. I can comment out the GetRollingResistance function call in Tick and everything works fine. I uncomment it and my pawn goes haywire again. I put in some UE_LOGs to output the values for the float AccelerationDueToGravity (Inside the function call) and a log for the new Force update in Tick (I took the force value and output it as a ToString() in the log. Now, all of a sudden, it all works fine! I comment out the log entries and it goes back to messing up again. I know I’ve used GetSafeNormal() in the VR course, but I’ve never come across GetGravityZ() before and I’m wondering if it is a compatibiliy issue with 4.23, but I don’t see anything in the documentation about it being deprecated or not. But, like I said, my code all matches the project exactly, it runs fine if I output the log values, then goes haywire if I comment the logs out.

void AGoKart::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

FVector Force = GetActorForwardVector() * MaxDrivingForce * Throttle;
Force += GetAirResistance();
Force += GetRollingResistance();
UE_LOG(LogTemp, Warning, TEXT("Force after Air and Rolling= %s"), *Force.ToString());
FVector Acceleration = Force / Mass;

Velocity = Velocity + Acceleration * DeltaTime;

ApplyRotation(DeltaTime);
UpdateLocationFromVelocity(DeltaTime);

}

FVector AGoKart::GetRollingResistance()
{
float AccelerationDueToGravity = -GetWorld()->GetGravityZ() / 100;
UE_LOG(LogTemp, Warning, TEXT(“ADTG= %f”), AccelerationDueToGravity);
float NormalForce = Mass * AccelerationDueToGravity;
return -Velocity.GetSafeNormal() * RollingResistanceCoefficient * NormalForce;
}

Which log messages make it work? Both of them or just one? It’s rare for logs to affect anything so I would make sure your compiling is working by restarting the editor.

Privacy & Terms