0

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

在此处输入图像描述

代码是:

// 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/

4

1 回答 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
.........
于 2020-04-12T10:24:58.913 回答