Page 1 of 1

jumping on moving platforms

PostPosted: Sat May 18, 2013 8:18 pm
by BogdansB
hey,
in my game i made a platform that move horizontal. my player should move with the platform so i made this code
player-> collision top reapeat=yes
Code: Select all
player.xvelocity=move_ground.xvelocity;



when i play it, and when he jumps on the platform, he moves with it but it looks like every time the platform changes the direction, the player slides some pixels away. looks like centrifuge .. :D

anyway, how can i make him move with the platform 1:1?

Re: jumping on moving platforms

PostPosted: Sat May 18, 2013 9:20 pm
by skydereign
First off, your code won't work if there are multiple moving platform actors with differing speeds. You should use this instead.
player -> Collision with top of move_ground (repeat) -> Script Editor
Code: Select all
xvelocity = collide.xvelocity;

This code makes sure the event actor and the actor it is colliding with are the ones being handled. It might not make much of a difference in your game right now, but you should strive to be clone specific any time.

Now that delay is caused by the ordering of events, where the collision event is being triggered before the step that causes the platform to change direction. Assuming the platform isn't moving fast enough to move past the player (stopping collision), you can just do the following.
player -> Collision with top of move_ground (repeat) -> Script Editor
Code: Select all
if(xvelocity==-collide.xvelocity)
{
    x += collide.xvelocity*2;
}

xvelocity = collide.xvelocity;

All that if statement does is compensate for the single frame distance gap caused by the two actors going opposite directions.

Re: jumping on moving platforms

PostPosted: Mon May 20, 2013 8:49 am
by BogdansB
ok thanks :D works just fine :wink: at first i had to change the collision with the titel but now its good :) thanks