Blender 2.6 Tutorial – Python Game Engine Programming – Part 1

Home/Programming Video Tutorials/Python Video Tutorials/Blender 2.6 Tutorial – Python Game Engine Programming – Part 1

Blender 2.6 Tutorial – Python Game Engine Programming – Part 1

FavoriteLoadingAdd to favorites

Part one in this series of tutorials for learning to use the Blender Game Engine via Python. It’s recommend that you are familiar with Logic Bricks from my Game Engine Physics series of tutorials. Plus, you should be reasonably familiar with Blender Python programming in general, which you can learn via a separate Playlist that I have uploaded.

By | 2017-06-03T01:14:49+00:00 June 3rd, 2017|Python Video Tutorials|50 Comments

50 Comments

  1. Sci Fi Animator June 3, 2017 at 1:16 am - Reply

    You’re very welcome. Thanks for following along.

  2. Sci Fi Animator June 3, 2017 at 1:17 am - Reply

    You’re welcome.

  3. Anu Malik June 3, 2017 at 1:19 am - Reply

    Hi,

    I’m new to BGE and learning it. can we use multiple blend files while creating a simple game. I’ve downloaded yo frankie and seen that there are multiple blender files but i actually don’t know how to use them. Could you help me with this problem. Thanks

  4. Anu Malik June 3, 2017 at 1:19 am - Reply

    Hey,

    Its ok, i found answer to my previous question. I have another question, could you tell me how can i use cycles material in BGE. I want to give my game realistic effect.

  5. WillTheGameDesigner June 3, 2017 at 1:19 am - Reply

    I’m trying to write a program where the camera watches an object move around. I need the trig functions within Python, but I can’t seem to find it. Can you help me?

  6. Antonio de Santa Gema Doblas Luna June 3, 2017 at 1:20 am - Reply

    My system is so much relentize whit GLSL… processor burning… but i like this tutorial.
    ¿can i to do the same whithout GLSL?… because i have only 2 Gb memory RAM and Video. Sorry my english.

  7. Maciej Miodunka June 3, 2017 at 1:22 am - Reply

    hey, I’m getting an error in  (line 9) if bge.logic.KX_ INPUT ACTIVE == keyboard.events [\[bge. events.UPARROWKEY]:the error says that plus "File "keyboard input", line 9 python script faildoes anyone have a clue?

  8. Sci Fi Animator June 3, 2017 at 1:25 am - Reply

    You’re very welcome. Thanks for watching.

  9. Sci Fi Animator June 3, 2017 at 1:25 am - Reply

    Great! Thanks for following along. There are many more tutorials in the pipeline.

  10. Sci Fi Animator June 3, 2017 at 1:27 am - Reply

    Hi there,
    Sorry, I really don’t know what they are doing with multiple files.

  11. Sci Fi Animator June 3, 2017 at 1:27 am - Reply

    Blender is challenging no doubt, especially with open source documentation, which is one of the weaknesses of open source software. Thanks kindly; I appreciate the feedback.

  12. TheMrkarsy June 3, 2017 at 1:27 am - Reply

    oke but i cant see real good what you have typed exactly
    could you type it down here maybe?

  13. Zak Brown June 3, 2017 at 1:28 am - Reply

    Ok works great 😀 good step by step in setup helpful for beginners like myself. Made a user mistake in code and was quickly helped with an answer. Thank you I’ll continue along.

  14. Anu Malik June 3, 2017 at 1:28 am - Reply

    Thank you for your help 🙂

  15. CardboardAnimation June 3, 2017 at 1:28 am - Reply

    is this software free?

  16. Sci Fi Animator June 3, 2017 at 1:29 am - Reply

    As I’ve been programming for years, I can tell you that 99% of the time it’s a programmer error. Look for common mistakes like missing colons at the end of If and While statements, or incorrect indentation (1 tab after new methods or conditional statements required) , accidentally using brackets or braces instead of parenthesis, etc. Sheer practice will get you there. It’s the best way! It can be a little frustrating as the errors returned in the Console can be a little vague. Good luck!

  17. blended head June 3, 2017 at 1:30 am - Reply

    I need a tutorial to run animations of a character in python. Anyone know of any out there? I have the animations and character and rigging all done. I can do it with logic bricks no problem. But I want to learn to do it in python with a script. Any help would be great! Thanks

  18. Elbarto Wicked June 3, 2017 at 1:31 am - Reply

    hi there,
    first of all thank for the time you invest in those tutorials
    second will be where can i find more information about things like * KX_INPUT_ACTIVE
    or UPARROWKEY, so want i mean is the syntax just for blender, what the difference in the bge and the normal blender scripting. just in case your answer to my second question is blender.org or blender artist , something more specific would be nice, like a link or a blender cheat sheet would be perfect.
    keep up the good work

  19. Sci Fi Animator June 3, 2017 at 1:31 am - Reply

    You’re welcome.

  20. Sci Fi Animator June 3, 2017 at 1:32 am - Reply

    It’s more likely that you have typo or programming error further down in the code which is causing that error.

  21. jovlem June 3, 2017 at 1:33 am - Reply

    Great stuff,
    Is there any advantage for using this method over the full "logic brick" method ( where you would use a keybord sensor instead of an always sensor ). 
    I mean, does one of the methods will have a better performance ( run faster ) or making it easier to convert it to an other platform ( like andfoid, I am using Gamekit )?

  22. Sci Fi Animator June 3, 2017 at 1:34 am - Reply

    Under the Help menu at top, select Toggle System Console. You have to then pick it up from the task bar. Or, for version 2.66 and later, it has moved to the menu to the left of the Help menu.

  23. Sci Fi Animator June 3, 2017 at 1:34 am - Reply

    No time for that. When I get my web site up and running I’ll put some example files on line. My work computer is never connected to the web and I have no direct access to those files right now anyway. Also, make sure your YouTube player is set to 720p as all my videos are uploaded at 1280 x 720.

  24. Sci Fi Animator June 3, 2017 at 1:36 am - Reply

    If you’re using the logic bricks with a keyboard sensor, you don’t need that part of the code. Logic bricks are quick to implement; using the Python approach gives you more power.

  25. Sci Fi Animator June 3, 2017 at 1:38 am - Reply

    It actually might be an error further down in the file; Blender Python is kinda weak on reporting the location of errors. Check for typos, missing colons at the end of conditional statements, the use of braces, brackets and parenthesis (sometimes they look like each other in the videos) and make sure to use tab to indent lines after the start of a method or conditional statement. I’ve seen that error before and I think it was always an error elsewhere.

  26. TheFMARiggerRockers June 3, 2017 at 1:38 am - Reply

    I actually take one of the examples from blender (If your open Templates>Python>GameLogic in the texteditor-.menu) and the Error is: ImportError: No module named ‘bge’ , but its imported 🙁 I decided to reinstall blender, but the error stays. Now I changed to 2.62, there all works.

  27. Sad Serenade June 3, 2017 at 1:40 am - Reply

    I like your name FirstGradeCalculus and your videos so i will subscribe.

  28. runizgozilla June 3, 2017 at 1:41 am - Reply

    For some reason i’m having a lot of trouble applying rotation to an object. There’s nothing on motion actuators in the most current python API, and i can’t figure out what the object property is! any help would be greatly appreciated

  29. Sci Fi Animator June 3, 2017 at 1:46 am - Reply

    You can reference the Mathematical functions via python.org.

  30. Hij ra June 3, 2017 at 1:46 am - Reply

    if you are having the error about importing bge try this line. "if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.UPARROWKEY] :
    player.localPosition.y += 1.0"

  31. TheFMARiggerRockers June 3, 2017 at 1:47 am - Reply

    I can’t import bge, it’s not defined … is this maybe, because I have 2.67? I couldn’t find an answer in the Changelog, can you please help me 🙂 ?

  32. Sci Fi Animator June 3, 2017 at 1:48 am - Reply

    Yes, you do not need GLSL for the logic bricks and Python. Thanks for watching.

  33. Ahmad Azizov June 3, 2017 at 1:48 am - Reply

    Very helpful, thank you a lot!

  34. Sci Fi Animator June 3, 2017 at 1:50 am - Reply

    You would have to render an image in Cycles and then use that as a texture map within BGE.

  35. Tom Mom June 3, 2017 at 1:52 am - Reply

    I too wanted to thank you for the lessons, so far I only have been working on the artistic side of Blender now there is some time for the logical part. It’s a good thing I had some experience with another programming language this makes it easier. Those tuts about the game engine physics are also great. GOOD JOB AND KEEP IT UP ( altough it’s easier said then done sometimes ^^ )!!!

  36. Sci Fi Animator June 3, 2017 at 1:52 am - Reply

    Yes, at Blender dot org.

  37. Areal Person June 3, 2017 at 1:53 am - Reply

    Ok, I’ve seen enough. I think It’s better to program your own game engine,
    because you will know it very well. And I think it is easy once you can program in C language. Also, Bricks are for people who don’t understand coding. If you know how to program then coding is just as easy as a IDE GUI to drag/drop and make settings.

  38. MrSweatCherry June 3, 2017 at 1:53 am - Reply

    Is this part of the script: keyboard.events[bge.events.UPARROWKEY] relevant? I think if we already have a sensor with up arrow, then we dont need to write it a second time in the script?

  39. Sci Fi Animator June 3, 2017 at 1:53 am - Reply

    It will be to your advantage to type in those green comments as well!

  40. MrSweatCherry June 3, 2017 at 1:54 am - Reply

    Okey thank you for the fast answer. Well I already guessed that i have more power with python, thats because i´m watching your tutorials ^^ great one btw, thanks a lot!

  41. Ahmad Azizov June 3, 2017 at 1:55 am - Reply

    1 question, how do i see the errors at runtime?

    Thanks!

  42. daniel monty June 3, 2017 at 1:56 am - Reply

    so somone please take a look at this and tell me whats wrong

    from bge import *

    def main():
        
        cont = bge.logic.getCurrentController()

        player = cont.owner
        
        keyboard = bge.logic.keyboard
        
        
        if bge.logic.KX_INPUT_ACTIVE = keyboard.events[bge.events.UPARROWKEY]:
            
            player.localPosition.y += 1.0

        return

    main()

  43. Sci Fi Animator June 3, 2017 at 1:57 am - Reply

    Thank you kindly. I’m just making all the tutorials that I wish that I had. Documentation for open source software always seems to a little behind, so I’m just trying to help everyone else come up to speed much quicker. Thanks for watching and helping to get the word out please.

  44. Sci Fi Animator June 3, 2017 at 1:59 am - Reply

    I don’t have any time right now to do any tutorials as I’m trying to catch up on the bills.

  45. Sci Fi Animator June 3, 2017 at 2:02 am - Reply

    You’re welcome. I’ll try and organize some links when I have time to work on the tutorials again and will place them on my web site, but finding good references is challenging at best which is why I made the tutorials in the first place. I’ll keep your question in mind. Thanks for watching.

  46. TheMrkarsy June 3, 2017 at 2:02 am - Reply

    SyntaxError: invalid syntax
    location: unknown location :-1
    i got this error 🙁

  47. TheFMARiggerRockers June 3, 2017 at 2:04 am - Reply

    So now all works fine, also with 2.67, but thank you for your help 🙂 (My anti-virus-program deleted the scripts-folder, i don’t know why, but the folder was on the blacklist. I can’t remember why i put this on it, but I will see what happen in next days^^)

  48. NTWFILMS June 3, 2017 at 2:06 am - Reply

    Some of the best Python tutorials on the internet.
    a thousand thanks for the time and effort you put into these.

  49. Areal Person June 3, 2017 at 2:11 am - Reply

    Thank you very much for all your hard work in presenting these.

    I’m looking forward to watching them.

  50. new video every day June 3, 2017 at 2:14 am - Reply

    if it is always running that code wont the function main be defined every frame, which seems like a waste of resources

Leave A Comment

*