Frame rate independent trace/sweep

How do I do it?

If my character is moving somewhat fast, and the player’s computer is somewhat slow, the sweep fails if the frame where it would have succeeded was skipped.

Unity has fixedupdate which is frame-rate independant, but I can’t find an equivalent. Without this the engine might as well be incapable of traces as the game will only appear to function, until played on a lower specced computer.

There’s no such thing really, the physX scene is locked, all traces are done, then it reports back what was hit IIRC.

Still it shouldn’t matter you can still detect collision even if an object has passed completely through another, that’s the idea behind a sweep.

Then the problem is getting the distance as shown in the code, perhaps that is the real issue, unfortunately there is no way for me to get the distance at the point it actually should have hit. The trace succeeding is insufficient information I need to know if the player is close enough to the hit location.

Even unity offers a fixed update, am I really getting stone walled by something this basic yet again in ue4.

Not sure what you mean there, FHitResult has a Hit Location in it? If the player is moving too quickly, you can modify the distance of the trace based on the delta of that frame.

You an use physics sub-stepping to simulate one movement in more ‘steps’ in one frame, which I think CMC does anyway. That would be the way to get around it, but there’s obviously a performance cost to that. There is no frame-rate independant update function in Unreal. I’m fairly certain that ‘Fixed Update’ in Unity still runs at your fixed framerate the same way “tick” does in unreal?

Have you tried enable Sub-Stepping? This should make Tick functionally equivalent to Unity’s Fixed Update.

Unfortunately even with sub-stepping, it’s not a perfect solution. A sufficiently high-speed character will still see problems even with the fixed timestep. Ideally, you would want to make sure that your logic sufficiently handles these cases, and by then, you shouldn’t **need **the fixed timestep.

There’s no hit location if it doesn’t hit. I was able to solve it by:

  1. Increasing the window for which the character can grab a ledge and calculating the correct position -> lerping over a small time, I’ll cover it up with animation if I feel the need but it looks fine at the moment.
  2. Tracing backwards over a frame, taking the position at the end of last frame and lerping between that and the current.

It looks like this:


uint8 SubSteps = 6;

for (uint8 i = 0; i < SubSteps; i++)
{
float SubstepAlpha = DeltaSeconds / SubSteps * i;
FVector FixedLocation = FMath::LerpStable(LocationAtLastTick, CharacterOwner->GetActorLocation(), SubstepAlpha);
}


Substepping wont work for this, the character isn’t being moved by physics. What you can do in a substep is extremely limited.