Changing platform speed

This topic is 907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So i had gotten a program that could move a platform from point A to point B and i tried to change the speed through duration for how long it takes to get there. no matter what value i put in it does not change the speed. Here is the Code.

// Called every frame
void AMovingPlatformShortDistance::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector PlatformLocation = GetActorLocation();
FVector Start = PlatformLocation;
FVector End = { -4763.913086,-1376.932129,249.404175};
float Duration = 3.0f; // seconds

FVector Delta = (End - Start) / 2;
FVector Origin = Start + Delta / 2;

float phase = sin(PlatformTime / Duration * 2 * 3.14);

PlatformLocation = Origin + Delta * phase;

SetActorLocation(PlatformLocation);
}

Share on other sites

FVector PlatformLocation = GetActorLocation();
FVector Start = PlatformLocation;

?

SetActorLocation(PlatformLocation);

Refer to my previous post, and as discussed in chat: Stop changing the starting point.

When you imagine your moving platform, you should see two fixed points in space: Where the platform should begin, and where the platform should end. The quoted code above implicitly changes the starting position to be the platform’s current position. Therefore, you should treat “Start”, “End”, and “Duration” as constant (read-only) properties of the platform:
Start    = {-4000.f, -1375.f, 250.f};
End      = {-4750.f, -1375.f, 250.f};
Duration = 3.0f;

PlatformTime += DeltaTime;

Edited by fastcall22

Share on other sites

Well even if you make this voodoo work you will still have non-linear speed. This is just too much work for a simple moving platform. I suggest:

S is the time the platform started moving

C is the current time

D is the time it takes for the platform to move from start point to end (Duration)

Delta = end position - start position

K = (C-S)%(2*D)

if K>D

current position = start position + Delta * (2*D-K)/D

else

current position = start position + Delta * K/D

1. 1
2. 2
Rutin
19
3. 3
4. 4
frob
13
5. 5

• 9
• 15
• 10
• 9
• 17
• Forum Statistics

• Total Topics
632603
• Total Posts
3007365

×