jumping on moving platforms

Talk about making games.

jumping on moving platforms

Postby BogdansB » Sat May 18, 2013 8:18 pm

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?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: jumping on moving platforms

Postby skydereign » Sat May 18, 2013 9:20 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: jumping on moving platforms

Postby BogdansB » Mon May 20, 2013 8:49 am

ok thanks :D works just fine :wink: at first i had to change the collision with the titel but now its good :) thanks
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest