简体   繁体   中英

Collision GameMaker issue

I'm new to GameMaker and I followed a tutorial by "Let's Learn This Together". I was trying to make collisions for my character, however every time my character bumps into the object, they get stuck and I can't control them anymore. I checked many times and I tried my own ideas, but nothing worked.

if(keyboard_check(ord("D")) && place_free(x + collisionSpeed, y)) {
    x += walkSpeed;
    image_speed = walkSpeed / 3;
    sprite_index = sClaire_Side_Right;
}

if(keyboard_check(ord("A")) && place_free(x - collisionSpeed, y)) {
    x -= walkSpeed;
    image_speed = walkSpeed / 3;
    sprite_index = sClaire_Side_Left;
}

if(keyboard_check(ord("W")) && place_free(x, y - collisionSpeed)) {
    y -= walkSpeed;
    image_speed = walkSpeed / 3;
    sprite_index = sClaire_Normal_Back;
}

if(keyboard_check(ord("S")) && place_free(x, y + collisionSpeed)) {
    y += walkSpeed;
    image_speed = walkSpeed / 3;
    sprite_index = sClaire_Normal;
}


if(keyboard_check(vk_shift)) {
    walkSpeed = 7;

}

if(keyboard_check(vk_nokey)) {
    image_speed = 0;
    image_index = 0;
    walkSpeed = 3.5;
    
}

If you're moving instnace by walkSpeed , you should also check for collision in distance of walkSpeed , not collisionSpeed .

If collisionSpeed is smaller than walkSpeed by just 1 pixel, then it might return no collision as it will be last pixel before collision happens.

A good example is when walkSpeed=3 , and collisionSpeed=2 , which will for sure causes instance to stuck inside solid objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM