[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Strategies for platformers



This is more of a general pattern than a particular comment on something people have said before. Instead of doing interference tests on the end-position bounding-box of the object, do interference tests on the shape bounding both the beginning and ending position bounding-box. That way, even if you're moving at > character height speed, you catch the interference, can integrate back to get the actual collision point, and call your collision-handler with the parameters. (This one of the general patterns used in 3D collision detection).

For bounding-box-based 2D geometry, the resulting form is a hexagon (or a quadrilateral that's just a special case of hexagon). 4 sides of the hexagon are grid-aligned, 2 are movement-vector-aligned. You use polygon-polygon intersection tests to check for collisions.

Enjoy,
Mike

Shandy Brown wrote:
...

Well, what I was trying to say above is that if you don't have the
charactor always falling (ie, if you set moveStateY=0), then as the
charactor moved sideways you'd have to check both the charactor's new
position for obstacles, and just underneath the charactor's new position
for support.

...

4 - How to avoid collisions with platforms when hero jumps from the bottom.
I did this by setting up an "upper edge" rect (for platforms) and a "bottom
edge" rect (for hero) and detecting collision on this "edges" instead of on
the full "sprite" rect. This approach does not work fine if movement is more
than one pixel per frame, as collision might occur "between frame".

So you want the charactor to 'bump his head' on platforms above him when
he jumps into them? Or to pass right through them on the way up?

...

_______________________________________
 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://members.rogers.com/mcfletch/



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org