Jump to content
  • Advertisement
Sign in to follow this  
Devin Ferriera

Changing platform speed

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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;
Additionally, you are missing a:
PlatformTime += DeltaTime;
Edited by fastcall22

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!