Reputation: 1
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;
}
Upvotes: 0
Views: 531
Reputation: 318
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.
Upvotes: 0