Game Engine - Shooting
PDFDownloads

This tutorial has worded directions along with the exact keystrokes it takes to get the step done. If you are fluent enough with Blender you may not have to look at the keystrokes line. Each step within the keystrokes line will be highlighted like this: Example. Arrows will indicate that you should be following a menu path.

This tutorial has a pre-made scene. If you want to download it you may, if not, I think you will still be able to understand the whole point of this tutorial. Within my scene, I have a plane with a bunch of cylinders upon it. I also have the camera set up with a gun right under it so when you play the game it will seem as if you are holding a gun. There is also a sphere. This will act at the bullet and in order for it to work you much put it on a separate layer. I left everything else on another layer. You can see the scene in the image below.

Most of the scene I have set up is mainly for demonstration but we will be working mainly with the gun and the sphere. But, if you are setting up your own scene and you want to put cylinders or something in it to shoot at we have to make the objects dynamic. I have already done this step with the scene I’ve pre-made in the download. Despite that, I am still going to go over it.

If you don’t know already, making something dynamic means to make objects movable within a scene. This is different from putting an animation in the game because the a dynamic object will move depending on whether or not something else touches it, or it hits something, etc. Dynamic objects will follow the rules of the physics in the game engine. To make an object dynamic all you have to do is select it, go into the logic panel and change the drop-down selection from static to dynamic.

Select Object, F4 (Logic panel), change static to dynamic

Now that you have gotten your desired object dynamic (if you made your own scene) we can start setting up the actual shooting of our weapon. To make a weapon shoot we will use a keyboard sensor and an ‘Edit Object’ actuator. First, we want to select our gun and go to the game logics panel. Once there we want to hit ‘add’ for each of our three columns.

Select gun, F4 (Logic panel), Hit Add for each column

As usual, we must connect the dots for anything to work. Under the sensors column (the left most one) change the ‘always’ setting to ‘Keyboard’. Then in the space where we choose the key, select a key you want to use to shoot with. I chose the space bar. Under the actuators column we will want to change the ‘Motion’ setting to ‘Edit Object’. Typically the default setting will be ‘Add Object’, if it isn’t for you change it to this. The next part is crucial. In the space where it says ‘OB:’ we need to type in the name of our bullet. In my case, it is just called ‘Sphere’. If you need to figure out what your bullet is named select your bullet, press ‘N’ to show the Transform Properties and the name should be shown in the appearing panel.

Connect the dots, Change sensor setting to Keyboard, Select your shooting key

Change actuator setting to Edit Object, Type in your bullet name in ‘OB:’

Now we need to make our bullet move when it appears. To do this we need to select our bullet, so go to the layer with our bullet and select it. In the logics panel change the objects setting from static to dynamic. Next we want to hit add for all of the columns and connect the dots. We will leave the sensor setting to always and change the ‘lin V’ setting. I made my 40 in the second column, the y-direction. Also, press the ‘L’ that is on the right of this row. This makes the bullet move relative to where the gun is pointing.

Select your bullet, F4 (logics panel), Set to dynamic, Press Add for each column, connect the dots

Change the Lin V setting in the second column to 40, select the ‘L’

Basically we have finished making our weapon shoot. There are many things we can do to expand upon this. Let’s make our gun turn so we can shoot at our cylinders. Go back and select our gun again and hit add for all of the columns twice. Connect all of the dots, and change the new sensors to Keyboard and make one setting to the left arrow and the other to the right arrow. In the actuator column we want to change the ‘Rot’ setting to .05 (left) in the third column and -.05 (right). If you get the numbers backwards you can always change them.

Select the gun, Press Add twice for each column, connect the dots

Change sensor settings to Keyboard, choose a key for each, and change the ‘Rot’ setting to .05/-.05 in the third column

Now press 0 to get into camera view and test out your game by pressing ‘P’. You should be able to turn your gun back and forth and shoot the cylinders off of the plane. This is all there is to it. This is just a basic rundown of how you can make a gun shoot and you can certainly change almost everything within the scene to make it work for your own preferences.