【问题标题】:Diagonal moving on slopes | GameMaker 2斜坡上的对角线移动 |游戏制作者 2
【发布时间】:2020-03-20 04:17:37
【问题描述】:

我正在尝试在 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/

【问题讨论】:

  • 你是如何控制垂直运动的,我没有看到 'y' 值和 vspd 有任何变化?

标签: game-maker gml game-maker-studio-2


【解决方案1】:

取自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
.........

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-17
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多