Blender 3D News and Training

Bow and Arrow – Part 2

Posted by Chris Plush on Sep 13, 2012

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.

Download the start file
Download the finished file

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

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