Hello guyse, i really dont understand collision detection, and i want it for my game. Anyone can tell me how to add a collision detection(just easy one) so you cant walk through walls.
Thanks from flezria
2D? 3D? Sprite based? Other?
Its in 2d, its going to be a space invaders game, when its done.
Just think of your sprites as rectangles. Each one will have a top, left, right, and bottom edges. Get the x or y coordinate value of each edge (assuming values get larger as you go down or right) , then compare them to see if they intersect:
Code:// if the top edge of one sprite is below the bottom edge // of the other, then no collision occurs. // do the same for the other four edges if (sprite1.topEdge < sprite2.bottomEdge) return false; if (sprite1.bottomEdge > sprite2.topEdge) return false; if (sprite1.leftEdge > sprite2.rightEdge) return false; if (sprite1.rightEdge < sprite2.leftEdge) return false; return true; // otherwise, they must have collided
Thanks alot for the help, ill take a look on it![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks