I won't be defending my approach as I don't have real claims for it and I understand why other approach are more convenient, but I'd like to pinpoint a couple of advantages (if bounding boxes won't change [much] during gameplay).
- To get the coordinates of the bounding box, you only have to add width and height for the bottom and rightmost borders, as he left and top borders will equal X and Y. Using the center, you have to perform calculations for all 4 boundaries.
- For collision, it has mentioned that you only have to check if the coordinates from both objects are within a abs(w1-w2)/2 range. I find it easier a x1 >= x2-w1 && x1 <= x2+w2. You can avoid the potential negative numbers playing around with the inequation: just do a x1+w1 >= x2 && x1 <= x2+w2.
- Translation between world coordinates to screen coordinates will be, in most cases, more direct.
Of course there are many other situations where you need to calculate the center (I do!). That's why I won't be defending my option (as it was, in the beginning, purely arbitrary).
Screenspace and tracking locations and stuff
Moderator: Moderators
Re: Screenspace and tracking locations and stuff
You know, I just realized that tracking from the center isn't going to have the offset problems I was thinking of.
If, that is, that I make sure all objects use even numbers in their dimensions. (Or all odd, but it makes more sense to use even, since the tiles are all 8x8.)
Yes, the object's center may be between two pixels, but this exact same thing is going to happen to the map, and all other objects. Everything will still be displayed properly.
The only difference is that when I check any arbitrary point, I need to look half a unit higher or lower, so that I can check the relative center of a displayed pixel. Otherwise I'm going to be checking a point in between two pixels.
If, that is, that I make sure all objects use even numbers in their dimensions. (Or all odd, but it makes more sense to use even, since the tiles are all 8x8.)
Yes, the object's center may be between two pixels, but this exact same thing is going to happen to the map, and all other objects. Everything will still be displayed properly.
The only difference is that when I check any arbitrary point, I need to look half a unit higher or lower, so that I can check the relative center of a displayed pixel. Otherwise I'm going to be checking a point in between two pixels.
-
psycopathicteen
- Posts: 3001
- Joined: Wed May 19, 2010 6:12 pm
Re: Screenspace and tracking locations and stuff
I heard that in games like Sonic that have a lot of slopes, that when a character is running up a slope, it checks wall collision several pixels higher in order to not get stuck in a wall that is under their feet. Do any games cut corners (quite literally, ha ha) by always checking walls several pixels higher, even while air bound, and snap the player up to the platform if they jump close enough to the top of a wall?