Path moving platforms trouble | Some help?

J

Jeshuakrc

Guest
Hi there. I'm new in GameMaker and in this comunity. I don't speak english pretty well, so excuse me some mistakes please.

I'm already getting in collisions an platform basics. After haver seen several tutorials and some nights, I made a simple engine, with jump and move mechanics. Then I added horisontal moving platforms, and it worked well; the nightmare comes up when I started with vertical platforms, you know, with the gravity and all of those things...

After some coding I achieved something like I wanted, but it is realiy bugged. That's my code:

Create event of my player:
{
msp=10
jump=25
hsp=0
vsp=0
grav=0.1
fall=0
}

Step event of my player:
{
//Input
Iright=keyboard_check(ord("D"))||keyboard_check(vk_right)
Ileft=keyboard_check(ord("A"))||keyboard_check(vk_left)
Ijump=keyboard_check_pressed(vk_space)

//H muveement
hspeed=msp*(Iright-Ileft)
if(place_meeting(x,y+2,all)){
with instance_place(x,y+2,all){
other.hspeed+=x-xprevious
other.vspeed+=y-yprevious
}
}

//V muvement / gravuty
fall+=grav
if fall>3 fall=3
vspeed+=fall
if place_meeting(x,y+1,all){
vspeed=-jump*Ijump
}

//colitions
if (place_meeting(x+hspeed,y,all)){
while(place_free(x+sign(hspeed),y)) x+=sign(hspeed);
hspeed=0;
}

if (place_meeting(x,y+vspeed,all)){
while(place_free(x,y+sign(vspeed))) y+=sign(vspeed);
vspeed=0;
}

if (!place_free(x,y)){
var iup=0 idown=0 ileft=0 iright=0
while!(place_free(x,y+iup)) iup-=1
while!(place_free(x,y+idown)) idown+=1
while!(place_free(x+ileft,y)) ileft-=1
while!(place_free(x+iright,y)) iright+=1

with instance_place(x,y,all){
other.hspeed=x-xprevious
other.vspeed=y-yprevious
}

if (min(-iup,idown,-ileft,iright)==-iup) y+=iup
if (min(-iup,idown,-ileft,iright)==idown) y+=idown
if (min(-iup,idown,-ileft,iright)==-ileft) x+=ileft
if (min(-iup,idown,-ileft,iright)==iright) x+=iright
}



//restart
if keyboard_check_direct(vk_escape) game_restart()
}

I know it isn't perfect and in fact it doesn't works fine. The player object colites well with static objects, and bahaves fine in horisontal moving platforms, but when a platform has a vertical muvement... welll... it can be seen the player objects getting inside the platform; the player object doesn't cupy the horsontal muvement of the platform very well; it also doesn't let me jump while moving in the platform. But i'll leave you a video in order to you see it with your eyes.


Thank you guys!!
 
Top