I'm working on making a 2D isometric engine in Java. I'm getting into collision detection and I've hit a bit of a problem.

Characters in-game are not restricted to movement from tile to tile - they move freely. My problem is that I'm not sure how to stop a player from colliding with, say, a crate, without denying them access to the tile.

For instance, say the crate was on .5 of a tile, and then the rest of the crate was off the tile, I'd like the player to be able to move on to the free .5 of the tile instead of the entire tile becoming blocked.

The problem I've hit is that I'm not sure how to approximate the size of the footprint of the object. Using the image's dimensions don't work very well, since the object's "height" in gamespace translates to additional floorspace being taken up by the image.

How should I estimate an object's size? Mind, I don't need pixel-perfect detection. A rhombus would work fine.

I'm happy to provide any code you might need, but this seems like a math issue.


You'll need to provide data (or explicit code) specifying the object's floor size. There's really no way for code to automatically figure out, for an isometric image, what portion of the image is flat on the ground, and what portion is vertical -- you'll need to specify that information yourself.

On the other hand, it's a fairly common thing to just treat the whole area encompassed by an object as unwalkable. If you allow the player to walk behind a large crate (for example), it's easy for him to go out of view, and no longer to know what's going on. So you might be able to just get away without doing anything special, if you're happy to do that.

  • \$\begingroup\$ I was afraid that might be the case. I really don't like the idea of making it entirely unwalkable, because that limits my ability to do things like archways or anything like a standing column, etc. \$\endgroup\$ Jan 17 '13 at 3:56
  • \$\begingroup\$ That said, its easy enough to define the shape of the footprint of, say, a crate, using the two faces pointing towards you and then drawing parallel lines for the two hidden faces. Is there some way of doing something like that with Java? \$\endgroup\$ Jan 17 '13 at 4:02
  • \$\begingroup\$ You're getting into the realm of machine vision, there, trying to get the computer to recognise shapes within an image and extrapolate. I suspect it'll be substantially easier to just tell the computer how big the object is. :) \$\endgroup\$ Jan 17 '13 at 4:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .