Help, implementation of Platform horizontal and vertical movement

J

Je7z

Guest
I need help creating a movingo platform, vertical and horizontal, is one of my biggest challenges, and all that I researched and tested, gave results. I've done almost everything I need for a platform-type platform, sloper, ladder, platform-through.
I need to know how I would put it on my platform, I'll be leaving the link to the project in github.

https://github.com/Je7z/New-Platform

Sem título.png
 

TheouAegis

Member
Well people have different ways of doing it. The way I do it is have a variable inside the player that can store the ID of the platform that he lands on. Set it to noone in the create event. When the player lands on a moving platform, store its ID in the player. In the players and step event, have him move based on the difference between the platform x-xprevious and y-yprevious. Perform any Collision checks which may occur as a result of the platform moving the player. Whenever the player jumps or walks off the platform, or it gets knocked off a platform if you incorporate not back, set the saved variable back to noone.

Handling platforms this way will allow you to have any number of players and any number of other instances such as enemies to ride platforms.
 
J

Je7z

Guest
I was able to make a horizontal movement, it is not perfect, but it helps, I'm having difficulties with vertical, the player gets good when the platform is going up, but when he goes down, he keeps jumping.

Code:
///Horizontal Move
if(place_meeting(x - 1,y,col_dir) || place_meeting(x + 1,y,col_dir)) {
    dir *= -1;
}

xVel = movespeed * dir;

xVelSub += xVel;
vxNew = round(xVelSub);
xVelSub -= vxNew;

x += vxNew;


with(instance_place(x,y - 1,par_player)) {
 
    if (!place_meeting(x,y + 1, par_MR) || (bbox_bottom < other.bbox_top)) {
       x += other.vxNew;
    }
   
}
 

TheouAegis

Member
Yeah, you need to tell the player that he's supposed to be riding the platform. which is what I addressed. If you just rely on place_meeting() checks or whatever, you will always have issues moving down because there's nothing below the player.

One idea I just had which I've never toyed with is to set the player's gravity to the platform's vspeed.
 
J

Je7z

Guest
I did what you said at the beginning, and with the horizontal platform, it worked very well !! but the vertical, I'm having problems, gets stuck with in 1 pixel on the platform, preventing the player from jumping and walking

1010.png

some way to correct this problem ?, I did the way you said, I do not know if it was right, the code is down

Code:
//Step Event - Player

//Platform Moving Horizontal
idplatformR = instance_place(x,y + 1,par_MR);
show_debug_message(idplatformD);

with(idplatformR) {
    other.x += x-xprevious;
    other.y += y-yprevious;
}

//Platform Moving Vertical
idplatformD = instance_place(x,y + 1, obj_platform_down);

with(idplatformD) {
    other.x += x-xprevious;
    other.y += y-yprevious;
}
 
Top