Re: Collision detection in 2d games when turning is a thing?

You have gone well beyond what BGT can do for you.  Leave for C++, C#, Python, or any other language wherein you can find bindings to either ODE or Box2d.  Learn and use those; Box2d is much easier than ODE, but ODE lets you use the collision stuff separate from the physics and you can just ignore Z.  Save weeks and possibly even months off your development time.  And here's the argument for why, presented as me telling you how this kind of math works.
So long as the only things that are turning are spheres, it's not so bad.  Anything beyond spheres means that you're going to need to do a lot of fiddly coding.  Even turning boxes isn't trivial-you'll almost certainly want to have 2D transformation matrices at that point.  If you stick to turning spheres and non-turning boxes (i.e. your game tiles), you can probably manage it to some extent.  That said, sphere-box is not the most trivial thing ever, especially if you allow the difference in size between the objects to go above a certain point.  In general, if there is a really big object and an extremely small object, a lot of the naive algorithms you're going to want to use go out the window, so it's probably best to avoid that.  Another thing that will cause problems is small, quickly moving objects.
To tell what tile you are hitting next, you need to add the unit vector pointing in the direction of the player's motion times the width of a tile to the player's position and check that.
Assuming east is 0, positive x is east, positive y is north,  and angles are both counterclockwise and in radians, the unit vector pointing in the direction of the player's motion is (cos(theta), sin(theta)).  Multiplying by the tile width gives (tile_width*cos(theta), tile_width*sin(theta)).  Add in the player's position: (player_x+tile_width*cos(theta), player_y+tile_width*sin(theta))
Wh ich, when converted to integers from floats, should be the indices.  If 0, 0 is in the top left and not the bottom left, you will need to subtract from the maximum x and y values or everything will be flipped oddly.  Otherwise, you can slightly redefine your coordinate system and go directly to a set of equations like those.  If you did not understand a word I just said, then go take a class in trigonometry or otherwise learn about it and then revisit this project: you'll really, really need to know trig well to do anything along these lines.  I can't give you the explanation of what sin and cos are without a diagram, and I can't communicate that across this forum.  This is why I am by necessity being quite terse here.  If you do understand what sin and cos are, and if the term unit vector has meaning, we might be able to effectively talk about doing this further, but the diagram wall exists right at that point and, if you've not see n them, it's near impossible to explain what's actually going on here.

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : tward via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Aprone via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Aprone via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Aprone via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Dranelement via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector

Reply via email to