0
\$\begingroup\$

I recently came across the game turbo tunnel. I want to make a similar game.

only thing that stands in my way is the collision detection. I first thought of learning plane line collision detection. But I didn't understand that stuff as I am too small(11th grade). I know gluunproject that uses coordinates on screen to world coordinates.

Things I thought about collision detection: -

  1. getting a physics library. (But I am not sure how do I use bullet).

  2. using box collision. (This solution may not work for irregular shaped doors) .

  3. third method is given below:-

    1) render the whole scene by plane's view.(no lightning, no textures)

    2) get the depth buffer at pixel at centre of screen.

    3) use gluUnproject for getting realworld coordinates of centre pixel. Let's say this point M.

    4) if the distance between plane and M is less than certain value then aeroplane blasts off.

    5) clear buffer bits and re render the scene with textures and lightning.

The third method is my idea. I am not sure if it is good to render the scene 2 times. But since only one object requires collision detection it may be a choice for me.

I am asking is using 3rd method to check for collision is good idea? if not So I should think something other.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

When I made my first game as a kid I didn't know trigonometry but wanted my player to turn and move freely in a plane, so I used a method that drew an arc onto the backbuffer (I also didn't know what to use the backbuffer for) which returned at what point the last pixel was drawn at, then I knew where to position my player on the front buffer.

In short, your third option would probably work just fine, you don't have to worry about drawing extra frames, most games today draw the screen multiple times for different 3D effects and still manage to get 60 fps or more. Don't worry about it until you see your game performance drop. And personally I think experimenting and playing around with things like you are doing is one of the best way to learn.

Your second option would work too, you just have to make each object you want to check collisions for have a list of collision boxes instead of a single one, this way you can have complex shapes like walls with holes in them simply by only putting boxes where there is a wall to collide with, leaving gaps where there should be.

The first option is a little overkill, physics engines work well but they are intended for having objects flying/rolling/falling freely, without being directly moved. They can certainly be used for collisions as well but unless you use the other features you won't gain much by using it.

Line and plane intersections would, again, work just fine. I'm not sure how much math you have learned yet though, but this video explains it fairly well as long as you know vectors and programming variables.

\$\endgroup\$
5
  • \$\begingroup\$ Wow! I didn't knew that most games draw the screen many times for 3d effects. So I will stick with method 3. Fairly simple and easy to understand. \$\endgroup\$ Mar 6, 2015 at 15:30
  • \$\begingroup\$ Is there any other option excluding those 3? \$\endgroup\$ Mar 6, 2015 at 15:31
  • \$\begingroup\$ @user3042253 The third option is not the usual way to do things, just like my use of drawing arcs to find a position isn't, but thinking your way around a problem is a great skill to have, even if the path you take is unusual. Line/box intersection, circle/rectangle collision detection, swept circle collision detection, physics engine are the methods that come to mind, and to optimize them you can look at quad trees, but it's only necessary if you get really really large levels. Those are all for when a character can only move in a plane, if you can jump and so on you might need 3d versions \$\endgroup\$ Mar 6, 2015 at 15:38
  • \$\begingroup\$ 3d versions like swept sphere instead of circle, sphere/box collisions instead of circle/rectangle and octree instead of quadtree. \$\endgroup\$ Mar 6, 2015 at 15:39
  • \$\begingroup\$ back them, a year ago. i didn't understand that video explaination. but now I watched and I understand it. \$\endgroup\$ Sep 9, 2016 at 11:29

You must log in to answer this question.

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