Jump to content
  • Advertisement


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


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

This topic is 5950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!