Jump to content
  • Advertisement
Sign in to follow this  
feti

OpenGL Isometric tile-based game and collision

This topic is 4034 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

When drawing isometric objects, how do I determine when the grip box of my player or of any other movable character or object for that matter has run into a solid object? If my object is loaded and it's a rectangle in 2:1 ratio and it's a slanted wall, do I have to provide coordinates for collision when it's loaded? All of the tutorials I've read online use a different non-opengl method where they take the grip box of the moving player and see if it crosses into a pixel on the slanted wall's texture that isn't classified as their transparency color. Article in question: http://www.inet2inet.com/inetforums/index.php?showtopic=325 Now, that won't work in opengl, because I've got a huge image file with multiple images on it that I will load into texture memory and work into my objects using texture coordinates. So determining transparent pixels so to speak isn't even an option. What options does an opengl isometric game have for collision in a scenario like this?

Share this post


Link to post
Share on other sites
Advertisement
You can try Picking using a SELECTION buffer, basically you render your solid objects into it once after loading the level and then see if the character box intersects with it for collision detection.

here is the NeHe lesson on picking, notice that you set "names" which are really integers for each different primitive (or collection of) that you want to distinguish between, you could use that in order to also give "properties" to the terrain (IE: Slippery, Sticky, Normal, etc).

Share this post


Link to post
Share on other sites
Thanks for the fast reply. I like the idea. However, I still have an issue.

These are my facts (for now):

1. I know the location and coordinates of the object.
2. I can determine when my player's 'grip' box touches another box.

This is the problem:

The texture applied to the rectangle is a rectangle itself, but the non-alpha data is slanted so it fits into the isometric style of the game. so even though the bottom left and top right corners of the rectangle exist, there's physically no texture data there, so if I were to go and calculate my grip box hitting the bottom left corner, it would collide and look as if the player walked into an invisible wall.

If you take a look here, you can see with the right wall how the collision wouldn't work.

What the ideal method would be is to calculate the alpha portion of what's in the texture and devise a collision box with the remaining pixel data. But that won't work for me because a wall or any other texture I use is part of a much larger texture atlas with 99 or so other images.

Share this post


Link to post
Share on other sites
Well, I think you can use masking to solve that problem.

I am not sure, haven't checked, but it should be possible to set the selection buffer to only plot names for the actual pixels rendered if it doesn't do so by default, so alpha blending should take care of that for you.

if everything else fails, you can always work in 3D with an ortho projection, using billboards for your character sprites.

Share this post


Link to post
Share on other sites
Just to extend a bit on the idea I originally proposed:

You have this (the dot between the matchstick man represents its X,Y location):



And after rendering a selection buffer, the selection buffer should look like this:



Then all you have to do is check if the next move would bring the character's location to be into a "blue" pixel, if so, take the action.

Of course using a single pixel for location should be extended to use a bounding box, and you obviously would want a different mask for the walls to handle the character wandering behind it, but you should get the idea. [smile]




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!