Categories

Thursday 5 March 2015

Collision checking part 1 of 2

This weeks post will be about my attempts to implement collision in our game.What was aimed for this week was to implement a collision system between the player entity and the walls in the game. To achieve this, a method for checking if shapes are overlapping is needed and a method of adjusting back the position of the overlapped objects in the right direction so that they are no longer intersecting.

example of  drawn collision shapes


Fortunately for us our tutor had uploaded an example for how to handle collision between two types of shapes. A axis aligned bounding box and a bounding circle. Basically the shapes are defined by a center point and a size. The size of the circle is a number defining its radius and the size of the box is defined by numbers representing the width and height from the center.

The shapes chosen for collision was a circle for the diver controlled by the player and boxes for the walls. The circle was chosen for the diver firstly because if it instead would have been a axis aligned box around the player, the corners of that shape could have collided with the walls collision shape without them visually even being close to a collision, and secondly because the diver will be rotated so that the head points towards the direction the diver is swimming in and thus we want the collision to be the same in any given direction. We were thinking about having multiple circle colliders with a specified relative rotation and distance from the player's center placed on the most important parts of the diver's sprite to get a more realistic collision, but we are going with one bigger circle from the center because we think it will be easier to implement and less resource heavy for the computer.

Unfortunately I have been having trouble understanding the code examples and to come up with a way to implement it because it was a hard coded example with collision checking between only two shapes and not 100 blocks or so simultaneously that our maps contain. Until now I have only managed to draw the collision shapes out and not check the collision between them, but only doing that the game started to lag because there are so many new shapes created and drawn out every frame.

So for the next week I will try to implement the actual collision as well as some optimizations for collision checking so that things do no longer lag.

No comments:

Post a Comment