The move-left-then-right workaround

It’s not clear to me if the tweak we make using movement +1 then -1 is to work around a bug maybe related to our choice of character? Or is this just like a standard Unreal thing you need to do if other actors are going to push your character around?

Well this is due to not using a physics based solution to movement. You would need to push things manually by sweeping.

const FVector CurrentLocation = GetActorLocation() + (PlatformVelocity * DeltaTime);
FHitResult Hit;
SetActorLocation(CurrentLocation, true, &Hit); // true is to sweep,
                                               // sweep hit results are stored in `Hit`
if (Hit.GetActor()) 
{
    UpdatePushedLocation(Hit);
    // this is needed again as the sweep sets the location to Hit.TraceEnd
    SetActorLocation(CurrentLocation);
}

////

void AMovingPlatform::UpdatePushedLocation(const FHitResult& HitResult)
{
    const double Distance = FVector::Dist(HitResult.TraceStart, HitResult.TraceEnd);
    const FVector Direction = PlatformVelocity.GetSafeNormal();
    const FVector Delta = Direction * Distance;
    HitResult.GetActor()->AddActorWorldOffset(Delta);
}
1 Like

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

Privacy & Terms