Mac OSX Hitting invisible wall on vertical collisions?

K

Kelsi

Guest
Hi there,

Total rookie here — So I've done my collision coding and it all works as it's expected to... except for in one direction.

If my player is above, to the left or to the right of an object wall, I will collide right up against it like I'm supposed to. But if I come up on the wall from below, I collide with an invisible wall WAY before I even get close to the wall. I've looked and looked but I'm not sure what I'm doing wrong or why my collision would work fine in every direction except one.

Here is what my collision code looks like in my move_state script:

Code:
// Horizontal Collisions
if (place_meeting(x+hspd, y, obj_wall)) {
     while(!place_meeting(x+sign(hspd), y, obj_wall)) {
        x += sign(hspd);
     }
    hspd = 0;
}

x += hspd;

// Vertical Collisions
if (place_meeting(x, y+vspd, obj_wall)) {
     while(!place_meeting(x, y+sign(vspd), obj_wall)) {
        y += sign(vspd);
     }
    vspd = 0;
}

y += vspd;
I hope my explanation makes sense. Let me know if I need to add more context. Like I said — novice here!
 

Relic

Member
I couldn't see an issue with this code. Check that the collision masks of your sprites (player and wall) are as you expect them to be. If one (or both) are larger than you think, this will cause your premature collision.
 
K

Kelsi

Guest
I couldn't see an issue with this code. Check that the collision masks of your sprites (player and wall) are as you expect them to be. If one (or both) are larger than you think, this will cause your premature collision.
Thank you, this was it! My bounding box was the size I wanted but it was located way up and to the left of my character!
 

Relic

Member
No problem - its only because I've banged my head against the same problem in the past that I could see the issue. Keep at it.
 
Top