tile-engine problem

Started by
4 comments, last by Zoomby 21 years, 2 months ago
hi! I have an annoying problem with my tile-engine. when the player (freely movable), hits a wall, i.e. a left-side wall, and you keep the left-arrow-key pressed, you can''t move up or down along the wall. This is because when a sprite collides with a tile, the sprite is moved back, until it collides no more. how can this problem be solved? bye chris
Advertisement
You could try only moving it back along the axis perpendicular to the wall... So if they hit a north-south facing wall you reset their x position so that they''re no longer ''inside'' the wall, but you leave their z position unaffected.
hi

The next problem is, I can''t really say which side of a Wall (Tile) the sprite hits. I tried something with vectors, but it''s sometimes inaccurate. Is there a good algorithm, to determine which side of a tile a sprite is hitting? Would this also work with a complex map (small tiles, and big sprites)?

bye
chris
What I do in my engine, is first try the move left. If that fails, bring the sprite back to it''s original position. Then try the move up. That one should succeed in your case. This method works great for me.
The method I use is a slightly more sophisticated variation of the OP''s approach: Before moving a sprite, check which directions it can move in. This is very simple: If the sprite is moving right, move it one pixel to the right and check for collisions, then move it back, et cetera.

If it''s trying to move in any direction that is blocked, set the velocity in that direction to zero. Once impossible movements are thus ruled out, move the sprite; if there are collisions, move it back (pixel by pixel) along the velocity vector until there are no more collisions; then it''s done.
thanks a lot! it finally works! :-)

This topic is closed to new replies.

Advertisement