N
NeZvers
Guest
I wanted to make alternative collision check for movements that don't involve while loop and end movements in one frame.
I found out that checking bbox side values turns out unstable (whatever what amount offset I tried it either goes into a wall or stays away), so I hardcoded offsets and that part works.
But I have a problem when next step will be inside and player obj isn't already next to the wall - player obj is hickupping for 1-2 frames before standing where it should have been (next to a wall).
here's my step event (GMS2), maybe someone can chime in and point out what's causing this isse.
I found out that checking bbox side values turns out unstable (whatever what amount offset I tried it either goes into a wall or stays away), so I hardcoded offsets and that part works.
But I have a problem when next step will be inside and player obj isn't already next to the wall - player obj is hickupping for 1-2 frames before standing where it should have been (next to a wall).
here's my step event (GMS2), maybe someone can chime in and point out what's causing this isse.
Code:
// Input check
var hinput = keyboard_check(vk_right)-keyboard_check(vk_left);
var vinput = keyboard_check(vk_down)-keyboard_check(vk_up);
//Horizontal speed
if(hinput!=0){
hspd += hinput * 1;
hspd=clamp(hspd,-4,4);
} else {hspd=0;}
//vertical speed
if(vinput!=0){
vspd+=vinput*1;
vspd=clamp(vspd,-4,4);
} else {vspd=0;}
//horizontal collision
if(place_meeting(x+hspd,y,oSolid)){
var solid_ = instance_position(x+hspd,y,oSolid);
if(hspd>0){
with(solid_){other.x= x + other.ml;} //ml = offset needed to be moved left
} else {
with(solid_){other.x=x+15 + other.mr;} //mr = offset needed to be moved right
}
hspd=0;
}
x+=hspd;
//Vertical collision
if(place_meeting(x,y+vspd,oSolid)){
var solid_ = instance_position(x,y+vspd,oSolid);
if(vspd>0){
with(solid_){other.y= y + other.mu;} //move up
} else {
with(solid_){other.y=y+15 + other.md;} //move down
}
vspd=0;
}
y+=vspd;
//clamp to room
x=clamp(x,0,room_width);
y=clamp(y,0,room_height);