debugging Gamemaker工作室:我的敌人跳出房间但只有当他们撞到左边的墙壁

ua4mk5z4  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(83)

我的敌人跳出了房间。它们与正确的墙壁碰撞并正确地反弹。然而,当它们撞到左边的墙壁时,它们会跳出房间并掉了出来。请帮帮我谢谢.这是在gamemaker工作室2,我正在创建一个平台游戏.

//Gravity and movement
vsp = vsp + grv;
//Dont walk off the edge

if (grounded == true) and (afraidofheights == true) and (!place_meeting(x+sign(hsp),y+1,oWall))
{
    hsp = -hsp;
}

//Horizontal collision
if (place_meeting(x+walksp,y,oWall))
{
    while (!place_meeting(x+sign(walksp),y,oWall))
    {
        //x = x + sign(walksp);
    }
    hsp = -walksp;
}

x = x + hsp;

//Vertical collision
if (place_meeting(x,y+vsp,oWall))
{
    while (!place_meeting(x,y+sign(vsp),oWall))
    {
        y = y + sign(vsp);
    }
    vsp = -jumpheight;  
}

y = y + vsp;

//Animations
//if the enemy is off the ground they use jumping and falling animations
if (!place_meeting(x,y+1,oWall))
{
    grounded = false;
    sprite_index = jumpsprite;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    grounded = true;
    image_speed = 1;
    //if the player is standing still plays idle animation
    if (hsp == 0)
    {
        sprite_index = idlesprite;  
    }
    //if the player is moving plays running animation
    else
    {
        sprite_index = runsprite;
    }
    
}

//Changes direction of sprite
if (hsp!= 0 ) image_xscale = sign(hsp) *size;
image_yscale = size;
4nkexdtk

4nkexdtk1#

我想问题可能是你的敌人精灵的起源。GameMaker的计算是根据对象当前精灵的原点进行的,所以如果两个精灵之间的原点不同或者不在精灵的中心,它可能会以不希望的方式移动对象。

相关问题