Author Topic: Vertical moving platform question  (Read 2723 times)

128-Up

  • Spike Dodger
  • Posts: 114
  • Lives are an antiquated concept.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 40.0.2214.91 Chrome 40.0.2214.91
    • View Profile
  • Playstyle: Keyboard
Vertical moving platform question
« on: January 24, 2015, 07:12:29 PM »
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

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 40.0.2214.91 Chrome 40.0.2214.91
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: Vertical moving platform question
« Reply #1 on: January 24, 2015, 09:01:12 PM »
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: [Select]
player.x += hspeed;
player.y += vspeed;

DO THIS INSTEAD:
Code: [Select]
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;
}

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.
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.

PlainZombie

  • Wannabe
  • Posts: 17
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 39.0.2171.99 Chrome 39.0.2171.99
    • View Profile
  • Playstyle: Keyboard
Re: Vertical moving platform question
« Reply #2 on: January 25, 2015, 04:42:59 PM »
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.
You make ONE GAME about Beavers...

128-Up

  • Spike Dodger
  • Posts: 114
  • Lives are an antiquated concept.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 40.0.2214.91 Chrome 40.0.2214.91
    • View Profile
  • Playstyle: Keyboard
Re: Vertical moving platform question
« Reply #3 on: January 26, 2015, 06:27:50 PM »
Looking at YoSniper's code... it looks like the Lemon code already has that? Maybe I'm missing something. ._.

Code: [Select]
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;
}

lemonxreaper

  • Administrator
  • Spike Dodger
  • Posts: 222
  • Do you even needle?
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 35.0 Firefox 35.0
    • View Profile
Re: Vertical moving platform question
« Reply #4 on: January 27, 2015, 05:07:12 AM »
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.
Just pretend I have a cool picture like Zero.
Completed Fangames: https://dl.dropboxusercontent.com/u/4678222/Complete%20Fangames.txt

nikaple

  • Trial Wannabe
  • Posts: 7
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 37.0.2062.124 Chrome 37.0.2062.124
    • View Profile
Re: Vertical moving platform question
« Reply #5 on: January 31, 2015, 08:09:08 AM »
Create a new object, solid, give it a blocky 32*32 sprite and the parent of it should be "block". Replace the roof block with this new object and you're done!

lemonxreaper

  • Administrator
  • Spike Dodger
  • Posts: 222
  • Do you even needle?
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 35.0 Firefox 35.0
    • View Profile
Re: Vertical moving platform question
« Reply #6 on: January 31, 2015, 03:11:27 PM »
I guess that just works on weird reading order lol.
Just pretend I have a cool picture like Zero.
Completed Fangames: https://dl.dropboxusercontent.com/u/4678222/Complete%20Fangames.txt