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.

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
    cont.activate(pull)

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

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




Related Posts

Comments (15)

avatar
Vadim Zalyubovskiy
Vadim Zalyubovskiy

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

Chris Plush

haha thanks!

Leg0her0
Leg0her0

this was super useful

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
Corey Windom

its a game…..who cares

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:
https://www.facebook.com/blenderWorks/

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.

SHEETAL

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

wpDiscuz