对角线在斜坡上移动| GameMaker 2

问题描述 投票:0回答:1

我正在尝试在GameMaker Studio 2中实现在斜坡上移动。它大部分时间都在工作,但是有时候当我试图向上移动时,我会陷在斜坡和地面之间。

enter image description here

代码是:

// Stop gravity on slopes
// When changing this to vsp = -1 I'm not getting stuck but the player is 
// currently jumping from 1 to 0 pixels...
if(place_meeting(x, y + vsp, slopes) && y > 0) vsp = 0;

在我的移动脚本中:

repeat(abs(hsp)){

    if(place_meeting(x + sign(hsp), y, slopes) && !place_meeting(x + sign(hsp), y - 1, slopes)){
        y -= 2;
    }

    if(place_meeting(x + sign(hsp), y, slopes) && !place_meeting(x + sign(hsp), y + 1, slopes) && 
    place_meeting(x + sign(hsp), y + 2, slopes)){
        y += 2;
    }

    // Horizontal movement  
        x += sign(hsp);
    }
}

我还在这里用我所有的代码创建了一个帖子:https://forum.yoyogames.com/index.php?threads/diagonal-moving-on-slopes.69667/

game-maker gml game-maker-studio-2
1个回答
0
投票

取自https://www.youtube.com/watch?v=1r1rElIiWqw

//Horizontal Collision
if place_meeting(x+hsp,y,par_wall)
{
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,par_wall) && yplus <= abs(1*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,par_wall)
    {
        while (!place_meeting(x+sign(hsp),y,par_wall)) x+=sign(hsp);
        hsp = 0;
    }
    else
    {
        y -= yplus
    }
}
x += hsp;

// Downward slopes
if !place_meeting(x,y,par_wall) && vsp >= 0 && place_meeting(x,y+2+abs(hsp),par_wall)
{while(!place_meeting(x,y+1,par_wall)) {y += 1;}}

// Vertical Collision
.........
© www.soinside.com 2019 - 2024. All rights reserved.