VERSION UPDATE: There’s a bug in latest blender versions that makes the arrow fall straight down when you pull the string all the way back. The problem was that when the pull animation reaches the last frame, it says it’s on frame 0 for some reason, so 0 velocity is applied to the arrow. To work around this I’ve added 4 lines after the « else » statement that sets the frame number to 40 if it returns as 0, and I changed the launcher.actuators line to use the variable « frame » defined by those 4 new lines. You can see it in the updated script below. Couldn’t figure out code formatting on youtube, so just replace [tab] tags with actually tabbing in there once or twice.
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:
[tab]pull.frameStart = 1
[tab]pull.frameEnd = 40
[tab]cont.activate(pull)
else:
[tab]if pull.frame == 0:
[tab][tab]frame = 40
[tab]else:
[tab][tab]frame = pull.frame
[tab]launcher.actuators[« add_arrow »].linearVelocity = [-(frame * 15), 0, 0]
[tab]pull.frameStart = 41
[tab]pull.frameEnd = 46
[tab]cont.activate(pull)
[tab]cont.activate(fire)
This is the second part of the bow and arrow tutorial series. Check out the first part(rigging a bow) at https://www.youtube.com/watch?v=jpsd0Aw1qvA
Download the start file for this tutorial here: http://www.cgmasters.net/tutorials/bow_game_start.blend
Download the final game here(textures won’t display in 2.75, but game logic works): http://www.cgmasters.net/tutorials/bow_game_final.blend
And here is the python script(updated for latest blender) that’s in this tutorial in case you have a hard time copying off the video:
Chris Plush (blengine)
Follow us on facebook at http://www.facebook.com/cgmasters
Source