Bow and Arrow – Part 2

Posted by Chris Plush on September 13th, 2012 | Comments (15)

VERSION UPDATE: There’s a bug in later Blender versions that make the arrow drop straight down when the bow string is pulled all the way back. To work around this I’ve added 4 lines after the “else” statement and changed the launcher.actuators line and that fixes it. Check out the updated script below:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
pull = cont.actuators["pull"]
fire = cont.actuators["fire"]
space = cont.sensors["space"]
launcher = bge.logic.getSceneList()[0].objects["arrow_launcher"]

if space.positive:
    pull.frameStart = 1
    pull.frameEnd = 40

    if pull.frame == 0:
        frame = 40
        frame = pull.frame
    launcher.actuators["add_arrow"].linearVelocity = [-(pull.frame * 15), 0, 0]
    pull.frameStart = 41
    pull.frameEnd = 46

If you don’t have your own bow to work with, download the start file for this tutorial here: bow_game_start.blend

Download the final game here: bow_game_final.blend

This is the second part of the bow and arrow tutorial series. Check out the first part(rigging a bow) here: Bow and Arrow Rigging

This tutorial will take you through taking our rigged bow and arrow from the last tutorial and putting it into the game engine in Blender 2.6. You’ll learn how to shoot arrows at different speeds depending on how far back the bow string is pulled, and how to have these arrows stick into whatever they hit.

Chapter List -

01:16 – Summary of how things are going to work
02:10 – Working with the arrows(duplicating to create a new dynamic arrow, parenting original arrow to the armature, and editing the bow animation to make the arrow pull back properly, changing physics properties, adding logic bricks)
07:10 – Summary of how the python script will work
07:40 – Adding logic bricks to the armature
09:15 – Creating a new python script
13:45 – Adding more logic bricks to the arrow
14:35 – Creating a new empty object to shoot arrows from(and adding logic bricks for it)
17:09 – Changing physics properties for the dynamic arrow
17:41 – Finishing the python script
21:40 – Adding logic bricks to the dynamic arrow to add artificial gravity and trajectory, and making it stick into things it hits
24:22 – Adding the “stick” property to objects in the scene
25:40 – Adding keyboard controls to rotate the bow

Chris (blengine)

  • http://Website vitos1k

    great! Love you’r tutorials, especialy the way you enjoying your creations :D Bulls eye!

  • http://Website jvo

    really awesome! i love the little game environment!

  • anandharaja

    Excellent Tutorial. Any chance to see score based game tutorial and Menu Creation?

    • Chris Plush

      definitely.. I can’t say when but all the game fundamentals like score, health, menus, and so on are all on the to-do list.

  • http://Website gonewild

    Superb tutorial! Well prepared and illustrated professionally! Hope to see more of these BGE tutorials. Will stick to this site permanantly like the arrow. Thank you!

  • http://Website SHEETAL

    Really awesome…… really improve my knowledge…..plz continue shareign your knowledge….

  • tarik bagriyanik

    here is my game:

    • Chris Plush

      Nice work! Sorry I missed this link before. That was 3 years ago, you’re probably a pro now. Made any games since?

      • tarik bagriyanik

        no problem Chris…
        from 2011 i share whatever i find here:

        • Chris Plush

          Cool collection there. I’ve just gotten into UE4 myself, seems like there’s so much potential there. I look forward to my first projects with it, though naturally I lament over the good old BGE days. But it’s time to move on.

  • http://Website archery fan

    Awesome tutorial. Just one thing, you should’ve put the arrow on the left side of the handle and rotated the bow to the right a bit. Right handed people generally hold the bow with their left hand and draw with their right; thus the arrow would go on the left side. For left handed people it’s the opposite.

    • Corey Windom

      its a game…..who cares

  • Leg0her0

    this was super useful

  • Vadim Zalyubovskiy

    You are amazing! Let`s kill it all! We need a crysis port to the blender.

    • Chris Plush

      haha thanks!