Archived

This topic is now archived and is closed to further replies.

Gollum

** Newbie ** - Simple tile-based collision detection questions

Recommended Posts

Gollum    122
Ok, first of all, I''m a newbie, but I know questions like this have been asked a million times. I''ve looked through a lot of archived posts, but not found exactly what I''m looking for. Here''s the situation: I have a tile-based map, which is a simple two-dimensional array (it''s in Python so technically it''s a list, but anyway) of square tiles. Each tile object stores things like its row and column, what jpeg to use for display, etc. Ok. So the next thing I did was to create some NPC''s that moved over the board. They hopped instantly (and at random) from the center of one tile to the center of any adjacent tile. Not very realistic. Step three. I make the NPC''s move at a certain movement rate, in pixels. So, now they move smoothly, check for screen boundaries, reach their destination, set another one, and start over. Infinitely. All very cute. Now here is where I hit my problem. I assume that we want our characters to move in pixel-based speeds, for smooth animation. But at the same time, I want them to use attributes of the tiles (defense modifiers, speed modifiers, etc.). At any given time, my units are very unlikely to rest entirely within a particular tile. So what do I do? Choose a pixel near the center of the unit, and have that decide which tile he''s on at a given time? Even more problematic is collision detection. Here''s my guess as to how I would do it: 1. Check to see if the next move will bring the unit into another''s bounding rectangle. If so, ---> collision. 2. Use pixel 15,15 (my units are 32px square) of each unit to figure out which tile they''re on. 3. Add in modifiers and complete the collision code. Is that right? And another dumb question while I''m at it - should the bounding rectangle be larger than the unit''s on-screen representation? In other words, should my 32 pixel square units have 34 pixel square bounding boxes? Thanks for answering another dumb newbie question, gollum

Share this post


Link to post
Share on other sites