Friday, July 31, 2015

JME3 and Collision Detection

JMonkey or JavaMonkey is a Java based 3D game development engine. In the developer community it is recognized as JME3. For more information you can visit their website http://jmonkeyengine.org/




Their IDE is just the same as the NetBeans environment.






I was just experienced the JME3 to learn collision detection. So for this experiment we're building a simple shooting game application. In the game play, player need to move his spaceship and shoot at the moving enemy objects, before, moving enemy objects collided with the spaceship. Main focus was to look at how the collision detection techniques are used in the game environment.

This post is not about building this app because you can follow this tutorial to create that state of the art game app.
It explains how to setup sounds, manage scene objects and its behaviors, and all the other things necessary  for a beginner, step by step, in a easily understandable way. 

Here we are in this post focusing on detect collisions. In a shooting game, typical collisions are enemy and the player, enemy and the bullets, or bullets and the player. As it decides the game-play, it is important to handle them.

So in our experiment, there are two types of collisions that are important to us. Enemies with bullets triggered by the player and enemies with the player spaceship.

In order to make enemies kill the player, we need to know whether enemies and the spaceship are colliding. Same as to kill enemies, we check whether enemies and bullets are colliding.

Radius Checking


To detect whether there is a collision, radius checking technique is a one solution. First we calculate the distance between the two objects in the center point. Next, we need to know how close the two objects need to be in order to be considered as having collided, so we get the radius of each spatial and add them. So, if the actual distance is shorter than or equal to this maximum distance, they collided.



So if the enemies and spaceship collided anyhow, game over and restart again.






No comments:

Post a Comment