Page 1 of 1

I need help with collision

Posted: Wed May 31, 2017 3:15 am
by Bikings
I'm making a little basic test game with a player and an enemy. I want the game to function so that when the enemy collides with the player, the player gets a GAME OVER screen. Does anyone know how to help?

Re: I need help with collision

Posted: Wed May 31, 2017 4:13 am
by Jasoco
Welcome! How good are you currently with coding? Do you know Lua or any languages?

You might want to look into some helper libraries like Bump (Which does collision and resolution with simple AABB rectangular boxes (No angled boxes or odd shapes) or HardonCollider. (Which does collision, but not resolution, between objects of many shapes including polygons and rotated shapes.

Resolution is what happens when something, say the player, collides with something else solid, say a wall. What happens in that case is the player is not able to overlap with the wall. Bump's resolution can make it so this happens and will do it for you automatically if used correctly. HardonCollider wouldn't perform any resolution so you can't have shapes automatically prevent overlapping like you can with Bump.

Then there's Löve's built-in Box2D which is more complicated to learn but can be powerful depending on the game. But it can take a lot of trial and error and variable tweaking to get it to work just the way you want.

In simple terms, you'd check for a collision between the player and the enemy every frame in the update, and when one happens, change the state of the game to a Game Over failure state.

Re: I need help with collision

Posted: Wed May 31, 2017 10:47 am
by Bikings
I know a little bit about lua

Re: I need help with collision

Posted: Wed May 31, 2017 10:55 am
by OnACoffeeBreak
Try going through some tutorials. I started with this one (http://sheepolution.com/learn/book/contents). It has a good gentle introduction to Lua and Löve.

Re: I need help with collision

Posted: Wed May 31, 2017 4:02 pm
by Bikings
Nevermind. I changed the circles to the rectangles so the collision was easier. Thanks for the help anyways