Skip to main content
gamedev.net
🔒 Locked

tile-engine problem

Started by Zoomby 4 replies 250+ views
Original Post
Zoomby
Zoomby
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
AndyGeers
AndyGeers
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.
Zoomby
Zoomby
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
Thrump
Thrump
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.
Miserable
Miserable
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.
Zoomby
Zoomby
thanks a lot! it finally works! :-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.