Section 55. Platform's Location Reset bug

Hello everyone, so on Section 55 of ObstacleAssault I’m having a problem with the platform’s location reset, basically what happens right now is:

Platform moves from 0 to 100
Teleports to 200
Moves back to 100
Teleports back to 0
Moves to 100

What should happen instead is a simple back and forth between 0 and 100, i looked at the code 5 times I see no difference between his and mine have i overlooked something?

Here’s code without comments:

FVector CurrentLocation = GetActorLocation();
CurrentLocation = CurrentLocation + PlatformVelocity * DeltaTime;
float DistanceMoved = FVector::Dist(StartLocation,CurrentLocation);
if (DistanceMoved > MoveDistance)
FVector MoveDirection = PlatformVelocity.GetSafeNormal();
StartLocation = CurrentLocation + MoveDirection * MoveDistance;
SetActorLocation(StartLocation); PlatformVelocity = -PlatformVelocity;

PlatformVelocity is (100, 0, 0) while MoveDistance is 100.

Your problem is on line 59. You’re setting the start location to the wrong thing, you want it to be the target location, which in a perfect world would be where it currently is.

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

Privacy & Terms