sinigrimi
Member
I'm trying to create perfect wall collisions like in one post from the forum, but my “oPlayer” skips through “oWall” from all sides except on the right. Help me find a mistake, please
create:
step:
upd:
I changed the code a bit in step event and now I have x-axis collision, but the y-axis does not work due to the x-axis, lmao. If I turn off the x-axis check, everything works on the y-axis. Help me please....
changes in step:
create:
Code:
player_stats[0] = 5 ; //speed
player_stats[1] = 100; //hp
player_stats[2] = 5; //damage
player_stats[3] = 500; //firing range
player_stats[4] = 1; //defence
sprite_bbox_top = bbox_top - y;
sprite_bbox_bottom = bbox_bottom - y;
sprite_bbox_right = bbox_right - x;
sprite_bbox_left = bbox_left - x;
Code:
var hspd = player_stats[0];
var vspd = player_stats[0];
if(keyboard_check(ord("W"))){
y -= vspd;
}
if(keyboard_check(ord("S"))){
y += vspd;
}
if(keyboard_check(ord("A"))){
x -= hspd;
}
if(keyboard_check(ord("D"))){
x += hspd;
}
if place_meeting(x,y,oWall) {
var wall = instance_place(x+ sign (hspd),y,oWall);
if (hspd > 0) { //right
x = (wall.bbox_left-1)-sprite_bbox_right;
} else if (hspd < 0) { //left
x = (wall.bbox_right+1)-sprite_bbox_left;
}
hspd = 0;
}
if place_meeting(x,y,oWall) {
var wall = instance_place(x,y+ sign (vspd),oWall);
if (vspd > 0) {
y = (wall.bbox_top-1)-sprite_bbox_bottom;
} else if (vspd < 0) {
y = (wall.bbox_bottom+1)-sprite_bbox_top;
}
vspd = 0;
}
I changed the code a bit in step event and now I have x-axis collision, but the y-axis does not work due to the x-axis, lmao. If I turn off the x-axis check, everything works on the y-axis. Help me please....
changes in step:
Code:
var hspd = player_stats[0]
var vspd = player_stats[0];
if(keyboard_check(ord("W"))){
vspd = -player_stats[0];
y += vspd;
}
if(keyboard_check(ord("S"))){
vspd = player_stats[0];
y += vspd;
}
if(keyboard_check(ord("A"))){
hspd = - player_stats[0]
x += (hspd);
}
if(keyboard_check(ord("D"))){
hspd = + player_stats[0]
x += (hspd);
}
NOTE: The solution is in the second message.
NOTE2: I have new problem case in the third message. [SOLVED]
Last edited: