0

I'm trying to make collision for a 2D game, the player (car) has to collide with the walls of the track when it hits them. I looked into pixel color detection, and X,Y -based collision (But since its a race track, which isn't square, I don't think this will be the best solution. Correct me if I'm wrong).

I understand the concept of collision for straight lines or squares, but i have no idea how to make a perfect collision in the corners of the track. example race track.

I've been searching the web a lot for tutorials and documents on this subject, but failed to find any real examples that don't use XNA or Unity. I need to find a solution that doesn't include using any kind of game engine.

Any links / documents / code snippets, or even pseudo code snippets would really help me a lot.

an example would be: Per Pixel Collision , the thing about this link is that it uses xna, which i can not use.

Community
  • 1
  • 1
FrankK
  • 482
  • 8
  • 23
  • Non-hardware accelerated pixel collision is a bad idea. Can you tell more about the game? Is it 2d, 3d? Maybe you could show us some code as well. – Stefan Oct 27 '15 at 14:12
  • the game is 2d, I cant really show any code because i don't know which solution i should go for, the collision i know how to make only works for square objects and straight lines. as in: if(player.x >= object.x && player.y >= object.y && player.x <= object.x + object.width && player.y <= object.y + object.height) – FrankK Oct 27 '15 at 14:13
  • 2
    just fyi there's a stackexchange for game development: http://gamedev.stackexchange.com/ – DLeh Oct 27 '15 at 14:14
  • You could put the track's info in a big matrix in memory. Combine this with the car's coordinates and you'll have the go/non-go areas. You can even put more info in the matrix such as bumb-factors and stuff like that. The downside: it might use a lot of memory, but if you order it correctly it performs like a charm. – Stefan Oct 27 '15 at 14:16
  • Can you use a physics engine? It sounds like exactly the sort of thing you're looking for. – 31eee384 Oct 27 '15 at 14:17
  • @31eee384 no engines at all – FrankK Oct 27 '15 at 14:20
  • My suggestion is to look into the Separating Axis Theorem (SAT) and approximate the edge of your track with a bunch of line segments. That should make it very simple to do the collision detection. (Collision resolution on the other hand can be difficult, especially when objects can rotate.) On the other hand, I don't think Stack Overflow is the place for this kind of question: in its current form it's a request for external resources and those aren't permitted. – 31eee384 Oct 27 '15 at 14:28

0 Answers0