X
xorphinindi
Guest
I'm having a problem with precise collisions in my 2D platformer.
Mainly, I have some sloped objects that I want the player to be able to walk up and down, but when I select the "precise" box, the player stops recognizing that the object exists at all.
I know I had slopes working correctly at some point, but that must have been months ago.
I don't remember what changed, but they certainly don't work now.
I'm not a great coder and most of what I have is modified from tutorials I followed when I was an even worse coder, but I can't see why this would be happening.
Thanks for any help.
"Collide and Move" is a player-script that runs during the player object's "normal" state.
All of the sloped objects I'm concerned with are parented to par_wall.
To clarify, regular (non-precise) collision with rectangular walls and floors is working fine; it's just the slopes that are broken.
Mainly, I have some sloped objects that I want the player to be able to walk up and down, but when I select the "precise" box, the player stops recognizing that the object exists at all.
I know I had slopes working correctly at some point, but that must have been months ago.
I don't remember what changed, but they certainly don't work now.
I'm not a great coder and most of what I have is modified from tutorials I followed when I was an even worse coder, but I can't see why this would be happening.
Thanks for any help.
"Collide and Move" is a player-script that runs during the player object's "normal" state.
All of the sloped objects I'm concerned with are parented to par_wall.
To clarify, regular (non-precise) collision with rectangular walls and floors is working fine; it's just the slopes that are broken.
Code:
/// Collide and Move
// Maintain momentum on elevator
if(instance_exists(obj_hqElevator)){
var vsp_final = vsp + vsp_carry;
vsp_carry = 0;
}
var hsp_final = hsp + hsp_carry;
hsp_carry = 0;
// Horizontal Collision
// Slopes
if (place_meeting(x+hsp_final,y,par_wall)){
yplus = 0;
while(place_meeting(x+hsp_final, y-yplus, par_wall) && yplus <= abs(1*hsp_final)) {
yplus += 1;
}
// pixel perfect horizontal collisions
if(place_meeting(x+hsp_final, y-yplus, par_wall)){
while(!place_meeting(x+sign(hsp_final),y,par_wall)) x += sign(hsp_final);
hsp_final = 0;
hsp = 0;
}
else{
y -= yplus;
}
vsp = movespeed / 2;
}
// Vertical Collision
if !place_meeting(x,y,par_wall) && vsp >= 0 && place_meeting(x,y+2+abs(vsp),par_wall){
while(!place_meeting(x,y+1,par_wall)) {y += 1;}
}
if (place_meeting(x,y+vsp,par_wall)){
while(!place_meeting(x,y+sign(vsp),par_wall)){y += sign(vsp);}
vsp_final = 0;
vsp = 0;
}
// Allow Movement
x += hsp;
y += vsp;