+ All Categories
Home > Documents > BGE Tutorial 3

BGE Tutorial 3

Date post: 04-Jun-2018
Category:
Upload: romieri
View: 223 times
Download: 0 times
Share this document with a friend

of 28

Transcript
  • 8/13/2019 BGE Tutorial 3

    1/28

    Part three of a series of tutorials for the Blender game

    engine by Smoking_mirror.

    Document Description:

    This is part three of a set of tutorials, it covers setting up a helicopter type character's weapons foruse in the BGE*.

    * Blender Game engine

  • 8/13/2019 BGE Tutorial 3

    2/28

    Document Aim:

    The aim of the tutorials is to introduce new users of the BGE to some of the concepts needed to

    produce a moderately complex game. The aim of this third tutorial is to show users how to set up

    their player character's weapons. A similar set up can e used for the enemy weapons

    Document Goals:

    !escrie how to ma"e a weapon's effects o#ect.

    $how how to integrate the shooting script.

    $how how to set up the ground and enemies so they can e damaged and register hits.

    $how how to ma"e the first steps of a asic %&! heads up display, or &(, user interface)

    Introduction:

    e've already made a game model and set up its movement profile, now we are getting to the fun

    part. (n this tutorial ('m going to show how to add weapons to your character. Again, ('m going to

    e supplying the scripts, all you have to do is set up the game o#ects as shown and plug in the

    scripts to your lend file y cutting and pasting.

  • 8/13/2019 BGE Tutorial 3

    3/28

    Document Inde:

    Part ! " #reating the $eapon effects. " Page %

    Part & " Setting up the player logic and ob'ects. ( Page !)

    Part * " Adding a +,D ( page &-

    Part % " Setting up the ground and enemies for collisions. ( page &)

    After$ord " page &

  • 8/13/2019 BGE Tutorial 3

    4/28

    Part /ne ( #reating the $eapon effects:

    e are going to give our character + different "inds of weapons. The original !esert $tri"e only had

    , ut we want to add more tactical challenge to the game y including anti-missile flares. The first

    weapon is the achine gun, or /mm cannon as it will e called in the %&!.

    hen creating the weapons effects we have two options. 0ne is to use a illoard type o#ect, a

    single plane which always faces the camera and loo"s the same from every angle. The other is to use

    planes set up li"e the gun flash aove. This has the advantage of eing ale to loo" different from

    different angles. 1ou should choose which to use in each case. A missile tail should use planes,

    while a small explosion might use the single illoard. There are also different types of transparencyyou can use. 2Alpha clip3 and 2alpha lend3 re4uire an alpha channel on your image. 2Add3 #ust

    re4uires that the ac"ground, and any part you want to e invisile e lac". 5or these ones we are

    going to use 2add3 type transparency. This loo"s est with the plane type o#ect.

  • 8/13/2019 BGE Tutorial 3

    5/28

    $o add a material to your weapon effect. Be sure to chec" the shadeless ox and set the game

    settings. hen you add a texture don't forget to set the &6 mapping7

    %ow you set up your materials and textures will depend on whether you are using the G8$8 mode ornot.

  • 8/13/2019 BGE Tutorial 3

    6/28

    1ou should go ahead and ma"e all the weapons effects. 1ou can also use animated textures as ('ve

    done with the 2ig9ang3 effect7

    (n the image window press 2n3 to open the option panel and set the game properties. hen ma"ing

    an animated texture you should have a numer of s4uares which can fit e4ually in to the si:e of the

    image. $o if you have a ;

  • 8/13/2019 BGE Tutorial 3

    7/28

    e need the 2gunflash3 o#ect as well as all the other pictured aove. (f the o#ect is not going to

    have physics set to 2no collision3) you #ust need the mesh. (f it is going to have collisions it's etter

    to parent the graphics mesh to a collision mesh. This can e a simple cue or rectangle, set to 2solid

    ody3 and with the invisile and ghost oxes chec"ed. This allows us to etter control the collision.

    $ee the missile aove, we only want the missile, not its tail, to register collisions. The oxes at the

    top are empties set up to carry a sound.

  • 8/13/2019 BGE Tutorial 3

    8/28

    1ou can set up the sound logic li"e this. 0pen the .wav file you've prepared, chec" the d sound ox

    and set the volume to whatever sounds right in game. 1ou need the following sound empties7

    1ou can also add the helicopter lades sound to your player o#ect. ?ust give it an always sensor and

    an A@! controller.

  • 8/13/2019 BGE Tutorial 3

    9/28

    1ou will need 4uite a few sounds for your pro#ect.

    http7www.freesound.org is a good place to loo" for sounds.

    This list should e enough though we may need to add more. ( will include these sounds with the

    Blend files, they will e pac"ed along with the textures.

    http://www.freesound.org/http://www.freesound.org/
  • 8/13/2019 BGE Tutorial 3

    10/28

  • 8/13/2019 BGE Tutorial 3

    11/28

    $et up the logic li"e this.

    5or the roc"ets and missiles you will have to add two properties7

    p9ullet means that this o#ect will e detected y enemy chec"ing to see if they have een hit. %it

    type sets the damage level and ma"es the o#ect e affected y flares if hit type ;).

    oc"ets should e hit9type C while missiles will e hit9type ;.

  • 8/13/2019 BGE Tutorial 3

    12/28

    1our missiles will also need some logic to ma"e them trac" to your target. 8eave the trac"ing o#ectox empty, it will e set y python.

    1ou also need some ullet hole type o#ects. They should lay flat on the ground.

  • 8/13/2019 BGE Tutorial 3

    13/28

    1ou need 2m9hole3, 2r9hole3 and 29hole3. They should e set to no collisions and they don't need

    any special logic. (n other games we might give them an animation to ma"e their appearance more

    natural, ut here they are going to e too small to notice.

    $o the o#ects you need are as follows7@ame Type Dhysics Droperties

    2gunflash3 eapon effect @o collisions @one

    2player9roc"et3 eapon effect $olid ody, ghost 2hit9type3 intC, 2p9ullet3 oolTrue

    2player9missile3 eapon effect $olid ody, ghost 2hit9type3 int;, 2p9ullet3 oolTrue

    2flare3 eapon effect $olid ody, ghost 2flare3 oolTrue

    2m9hole3 eapon effect @o collisions @one

    2r9hole3 eapon effect @o collisions @one

    29hole3 eapon effect @o collisions @one

    2small9ang3 eapon effect @o collisions @one

    2ig9ang3 eapon effect @o collisions @one

    2mg9sound3 eapon sound @o collisions @one

    2roc"et9sound3 eapon sound @o collisions @one

    2missile9sound3 eapon sound @o collisions @one

    2missile9hit3 eapon sound @o collisions @one

    2no9ammo3 eapon sound @o collisions @one

  • 8/13/2019 BGE Tutorial 3

    14/28

    1ou can set up the flare o#ect to have animations, #ust li"e the explosions, ut you need a slightly

    different set of animation curves7

  • 8/13/2019 BGE Tutorial 3

    15/28

    Part t$o ( Setting up the player logic and ob'ects:

    e want to add some empties to our player o#ects, we need three empties called...

    ...roc"ets9right, roc"ets9left and m9gun. The empties are where the weapons are going to e fired

    from. Darent them to the player mesh, or to the roll action o#ect the circle).

  • 8/13/2019 BGE Tutorial 3

    16/28

    e also need an empty set way out in front of the chopper called 2null9target3.

    This also needs a property called 2null9target3.

    (t's est to set his o#ect a little lower than your chopper and parent it to the roll action o#ect. This

    is what your guns will aim at if they have no enemy target, so you #ust want them to fire at the floora little way in front of the helicopter.

  • 8/13/2019 BGE Tutorial 3

    17/28

    @ext we have to give our player o#ect some new properties. $et them up #ust li"e in the pictureaove. 2target9o3 and 2enemy3 are oth strings, they can store any information here, in this case

    we are going to e storing references to o#ects in game. 2target9o3 will e the 2null9target3 o#ect

    we created aove, while enemy will e the closest enemy to the player, if they are in the correct arc.

  • 8/13/2019 BGE Tutorial 3

    18/28

    This is the logic set up. (t has #ust two sensors and three actuators.

  • 8/13/2019 BGE Tutorial 3

    19/28

    Be sure to add each actuator and sensor as shown. 1ou can increase or reduce the numer of logic

    tic"s on the left mouse utton sensor to get faster or slow firing weapons.

    The python module is7cobra.cobra_shooting

    At this point you should get the new script from the place you got this tutorial. ?ust cut and paste it

    over the old cora.py script in your text window. All the new code has een added to this script.

    1ou may have already added the helicopter sound in the last section. ?ust connect it to the same

    always sensor as the helicopter lades. e will e changing that in future, ut for now it's nice to

    hear the 2whup-whup3 sound as your chopper flies around the screen.

  • 8/13/2019 BGE Tutorial 3

    20/28

    Part three ( Adding a +,D:

    There are several ways to handle adding a %&! or &( to your games. 0ne of the most common is to

    add a overlay scene. %owever we are going to "eep things simple and simply add some o#ects to

    the scene parented to our camera.

    Add a simple plane to the scene and parent it to the camera so its rotation matches the camera.

  • 8/13/2019 BGE Tutorial 3

    21/28

    Ad#ust the position in the view so it is in the ottom right hand corner.

    Give the o#ect a property called 2amount3. Freate a new action for the weapon display o#ect to setthe o#ect color li"e we did with the explosions and flare aove).

  • 8/13/2019 BGE Tutorial 3

    22/28

    @ext we need to add some more properties to the camera7

    And we also need to add some more actuators to the camera and display o#ect7

    a"e sure you set the action to 2property3 not 2play3. The actions should e 2display switch3 and

    2color9code3. e want the player to see if they are running out of ammo, ut we don't want to get

    in to using text yet, so we are going to show ammo levels y color.

    2Amount3 is the property which drives the color change of the weapon display o#ect. (t has to e

    on the o#ect, not on the cam.

  • 8/13/2019 BGE Tutorial 3

    23/28

    Freate four o#ects on another layer, you will need a new texture for this, ('m using this one7

  • 8/13/2019 BGE Tutorial 3

    24/28

    The arrow and power ar will e used later to show fuel, armor and nearest enemies and o#ectives.

    @ame the meshes of the o#ects as follows7@ame7 epresents7

    $eapon_display_! achine gun

    $eapon_display_& oc"ets

    $eapon_display_* issiles

    $eapon_display_% 5lares

    1ou should e careful how you set up the o#ect color action. (t should fade from pale green at /

    frames towards dar" red at C// frames and then lac" at C/C frames.This should give the following result7

    hen you are out of ammo the image goes lac".

    1ou should also create a lan" mesh move the verts on the &6 image so they are covering a

    transparent part of the image) and call it 2empty9display3. This will e displayed if your chopper has

    no weapons. (f you did everything correctly you should now e ale to fly around and fire your

    missiles, ut they don't explode. $o how do we handle that

  • 8/13/2019 BGE Tutorial 3

    25/28

    Part four ( Setting up the ground and enemies for collisions:

    Add some cues to your scene. a"e them static and give them the following properties7

    @ext set up their logic li"e this7

    The python module is7cobra.player_weapon_hit

    and the collision sensor should e chec"ing for the property 2p9ullet3 rememer it's the property

    you gave the player's missiles and roc"ets earlier).

  • 8/13/2019 BGE Tutorial 3

    26/28

    !o the same with the ground in your scene7

    But don't give the ground the 2health3 property, instead it needs the 2ground3 property. 1ou will

    need to give all enemies and uildings this set up if you want them to e shootale. 0#ects with

    the 2ground3 property will accept missile and roc"et craters. 1ou don't want to give this property to

    small o#ects such as flagpoles and people ecause they are smaller than the crater and it'll loo" li"e

    the crater is floating in mid air. (nstead use it on things li"e large uildings.

    @ow when you fire your weapons the missiles and cannon should automatically trac" the enemy

    o#ects, and they should register explosions. (f you cause enough damage you can destroy the

    enemy o#ects.

    8ater we are going to set up enemy so they explode when destroyed, ut for now have fun firing

    your weapons.

  • 8/13/2019 BGE Tutorial 3

    27/28

    I01e added a ne$ player model to the blend file that goes $ith this tutorial. If you change

    the player ob'ect adder to add 2player_alt3 you can en'oy flying around in a classic

    ,+"! +uey. 4his $ill be part of a later tutorial focusing on changing the player ob'ect to

    add more 1ariety to missions 5in the ,+"! you $ill be able to pick up passengers6.

    7et time $e $ill look at making enemies and gi1ing them simple AI. 4hanks for

    reading. If you ha1e any 8uestions please post them in the Blender artists thread.

    Smoking 9irror AA Pickledte;cat AA

  • 8/13/2019 BGE Tutorial 3

    28/28

    (f you want to write your own tutorials to e included in the series you should use the following

    formatting conventions7

    ain Title7 $egoe Drint ;= point, Fentered.

    $utitles7 $egoe Drint C= point, left aligned.ain text7 $egoe &( $emiold C= point, left aligned.

    (mage captions7 $egoe Drint C= point, Fentered.

    The document should e landscape, not portrait for etter viewing on wide screen monitors without

    splitting pages, and images included should e of a maximum with of


Recommended