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

If no one has told you, velocities can also be represented as unit vectors times a magnitude.  I am almost certain that you know this.  You probably want to use your velocity vector as the place to check, not the vector represented by the player's facing direction.  If velocities can ever be more than one tile per tick, you'll run into teleportation through walls issues; for that reason, you may wish to only keep the unit vector and drop the magnitude.  In either case, it will fix your issues with only colliding with walls in front, at least if the player can move in other directions besides forward.
Atan2 is the function which you are thinking of: given x and y, it gives you an angle.  You will probably never use this for collision detection.  The only time the angles matter much is in displaying to the player.  Collision detection is normally implemented with rotation matrices, another concept that I spent a very long time unders tanding and which I cannot easily convey here.  So long as you use only the tile map and spheres, you can entirely avoid them.
But I still say use a library.  Doing this well took many people a pretty long time, and I think that if you're trying for this kind of simulation, box2d is probably the best fit.  You'll spend some time learning to understand it, and it's of course possible you don't know other languages, but it will avoid a lot of debugging and math and stuff while also giving you every feature you'd ever need and then some.  This advice is assuming that you just want a game.  I figure any programmer at the point of considering this kind of thing can probably pick up another language pretty quickly, and if it's the kind of game you're going to want to write, it's worth it, at least in my opinion.  I'd suggest at least reading some Box2d tutorials at this point--there are some things about it th at might put you off, namely that you talk about forces and not velocities, but it's still worth looking at even if you decide not to.

_______________________________________________
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 : 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
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector

Reply via email to