Fangames > Programming Questions

Vertical moving platform question

(1/2) > >>

128-Up:
I'm using the Lemon Engine on 8.0 and noticed that if the Kid stands on the moving platform going upwards, when the platform hits a ceiling the Kid is pushed into the ceiling. Some games make it so that the Kid just drops through the platform if that happens. What do I do to make that happen?

YoSniper:
Within the step code for the platform, I recommend putting something like this where the code sets the player's x and y relative to the platform.

RATHER THAN SAYING SOMETHING LIKE:

--- Code: ---player.x += hspeed;
player.y += vspeed;
--- End code ---

DO THIS INSTEAD:

--- Code: ---globalvar space_available, hsp, vsp;
space_available = true;
hsp = hspeed;
vsp = vspeed;
with(player) {
    if not place_free(x + hsp, y + vsp) {
        space_available = false;
    }
}
//Finally, set the player relative to this platform's movement if it is deemed that space is available
if space_available {
    player.x += hspeed;
    player.y += vspeed;
}
--- End code ---

NOTE: This will not work if the platform is moving diagonally. In such a case, you will need to check the horizontal and vertical available spaces separately.

PlainZombie:
Hope you don't mind me asking a separate question RE: Vertical Platforms. This is the Yuutuu engine. Collision with niseblocks works from the bottom, left, and right of the platforms just fine. But for some reason collision with the top of the platforms doesn't work as intended and the moving platforms pass right through without changing direction. This is all standard Yuutuu code for moving platforms I haven't added anything new so it's weird that this specific instance doesn't work for moving platforms.

128-Up:
Looking at YoSniper's code... it looks like the Lemon code already has that? Maybe I'm missing something. ._.


--- Code: ---if (!place_free(x+hspeed,y)) {
    hspeed=-hspeed;
}
if (!place_free(x,y+vspeed+yspeed)) {
    if (vspeed!=0) {
        yspeed=-vspeed;
        vspeed=0;
    }
    else {
        vspeed=-yspeed;
        yspeed=0;
    }
}

y+=yspeed;
if (place_meeting(x,y-2,player)) {
    player.y+=vspeed+yspeed;
    with (player) {
        if (place_free(x+other.hspeed,y)) player.x+=other.hspeed;
    }
}

if (place_meeting(x,y+2,player2)) {
    player2.y+=vspeed+yspeed;
    with (player2) {
        if (place_free(x+other.hspeed,y)) player2.x+=other.hspeed;
    }
}

if (vspeed<0) {
    yspeed=vspeed;
    vspeed=0;
}
if (yspeed>0) {
    vspeed=yspeed;
    yspeed=0;
}
--- End code ---

lemonxreaper:
I normally put invisible killers inside of blocks that players can be pushed into, like a squishing death. however,
I know I got something like what you want to work before but I cant remember the coding for now.
I suppose for an easy way you could make an object that preforms a while loop when contacting the player to push them down.

Navigation

[0] Message Index

[#] Next page

Go to full version