phase through walls glitch

P

piksil_demon

Guest
so my problem is that when i press up against the wall, then rotate my character, the corners of it clip into the wall and i glitch though. this happens with rectangular, elipse, and presice collision. i know the sollution but i dont know how to make it. what i want to do is if part of my body it touching the wall, i cant turn any more in that direction (im using a square model).
another problem im having is that its not pixel perfect collision. if you can help with that aswell then big thanks. here is my move and colision code-
//variables
var up, down, left, right, arrow;
up = keyboard_check (ord('W'));
down = keyboard_check (ord('S'));
left = keyboard_check (ord('A'));
right = keyboard_check (ord('D'));


//player movemnt
//image_angle = point_direction(x, y, mouse_x, mouse_y);
old_angle = image_angle;
image_angle = point_direction(x,y,mouse_x,mouse_y);
if place_meeting(x,y,obj_wall) {
image_angle = old_angle;
}

x+= (right - left)*spd;
y+= (down - up)*spd;

if speed > spd {speed = spd;}




//collision
if(place_meeting( x + spd, y, obj_wall) ){
x -= spd;
}
if(place_meeting( x - spd, y, obj_wall) ){
x += spd;
}
if(place_meeting( x, y + spd, obj_wall) ){
y -= spd;
}
if(place_meeting( x , y - spd, obj_wall) ){
y += spd;
}
 
J

jackhigh24

Guest
why dont you use if not place meeting then that way you wont change the image angle while place meeting, also at the moment you are setting old image angle to the same as image angle so it will still be the current image angle

so instead of this
Code:
//image_angle = point_direction(x, y, mouse_x, mouse_y);
old_angle = image_angle;
image_angle = point_direction(x,y,mouse_x,mouse_y);
if place_meeting(x,y,obj_wall) {
image_angle = old_angle;
}
do just this
Code:
//image_angle = point_direction(x, y, mouse_x, mouse_y);
if !place_meeting(x,y,obj_wall) {
image_angle = point_direction(x,y,mouse_x,mouse_y);
}
 
P

piksil_demon

Guest
why dont you use if not place meeting then that way you wont change the image angle while place meeting, also at the moment you are setting old image angle to the same as image angle so it will still be the current image angle

so instead of this
Code:
//image_angle = point_direction(x, y, mouse_x, mouse_y);
old_angle = image_angle;
image_angle = point_direction(x,y,mouse_x,mouse_y);
if place_meeting(x,y,obj_wall) {
image_angle = old_angle;
}
do just this
Code:
//image_angle = point_direction(x, y, mouse_x, mouse_y);
if !place_meeting(x,y,obj_wall) {
image_angle = point_direction(x,y,mouse_x,mouse_y);
}
because that dosnt solve the problem i posted about
 

TheouAegis

Member
What if you moved the angling code to the end of the code?

Also, if you want pixel perfect, you need to loop through all angles until there is no longer a collision.

while place_meeting(x,y,obj_wall)
image_angle -= sign(old_angle - image_angle);
 
P

piksil_demon

Guest
What if you moved the angling code to the end of the code?

Also, if you want pixel perfect, you need to loop through all angles until there is no longer a collision.

while place_meeting(x,y,obj_wall)
image_angle -= sign(old_angle - image_angle);
how do you mean?
 

TheouAegis

Member
In your code, you just have "if there is a collision after rotating, go back to the old angle". But for something more pixel perfect, you'd need to instead have "if there is a collision after rotating, slowly rotate back to the old angle until there is no longer a collision".

I just realized though in my sample code that I didn't account for the angle difference being greater than 180.
 
P

piksil_demon

Guest
In your code, you just have "if there is a collision after rotating, go back to the old angle". But for something more pixel perfect, you'd need to instead have "if there is a collision after rotating, slowly rotate back to the old angle until there is no longer a collision".

I just realized though in my sample code that I didn't account for the angle difference being greater than 180.
can you show me what you mean by changing my code? telling me "do the thing in the place" is just as confusing as telling me "dont do it"
 

TheouAegis

Member
if place_meeting(x,y,obj_wall) {
while place_meeting(x,y,obj_wall) {
image_angle -= sign(angle_difference(old_angle,image_angle));
}
}
 
P

piksil_demon

Guest
if place_meeting(x,y,obj_wall) {
while place_meeting(x,y,obj_wall) {
image_angle -= sign(angle_difference(old_angle,image_angle));
}
}
where in my code do i place that? can you copy, paste, and replace what i have?
 

TheouAegis

Member
Hm. Oh, I think I needed to reverse old_angle and image_angle. The easier fix would be to just change -= in my code to +=. If that still causes freezing, you can try this:

Code:
old_angle = image_angle;
image_angle = point_direction(x,y,mouse_x,mouse_y);
if image_angle != old_angle {
    if place_meeting(x,y,obj_wall) {
        while place_meeting(x,y,obj_wall) {
            image_angle += sign(angle_difference(old_angle,image_angle));
        }
    }
}
 
Top