Download presentation
Presentation is loading. Please wait.
1
Blender API: Part 2: Game Engine
Roger Wickes
2
Game Engine Use Blender to model, UV texture, animate, etc.
Makes a Windows .exe file for royalty-free distribution for PC play only Competes with Unity, Lumberjack Each object has a logic tree, evaluated at a Frame Rate: Sensor-Controller-Actuator (SCA) Sensors: keyboard, joystick, network, timer, always, ray, radar, near, collision Controllers: And, Or, etc. Python Script or Module Actuators: Motion, Message, Camera, Scene, Constraint, Action, … Actions via any kind of shape keys, bone-actions. Triggered by sensor – event or timer (e.g. idles) Animated textures via sprites sheets, sequences, or movies. Standard color diffuse, normal bump maps, reflection (spec) maps. Particles work as well Objects can be subject to physics: gravity, force fields Motion can be recorded for use in non-game action
3
Python API (Controller)
#Land Mine methods import bge, bpy def Explode(controller): obj = controller.owner hide(obj) sprite = Sprite(obj, ‘FIREBALL’) print(“%s exploded.” % obj.name) def hide(obj): # move object to non-game layer # so it cannot explode again pass Class Sprite(): def __init__(self, obj, sheet): # create textured plane with sheet # put plane at obj position # orient to face scene camera # play animation once # call back to remove plane from scene Import bge Import GameLogic Import Physics Real-time debugging
4
dir(bge) ‘app’ – the blender application itself; version
Special mention: bpy.game
5
World setup Sets background; can be color or image texture
Use HDR images for a world and observable sky Mist helps with Occluding far off objects not of interest
6
Scene setup Blender Render Set Blender Game renderer
Set Gravity (if you use Rigid Bodies) Rigid Body World Set Blender Game renderer Enables Nav Mesh for path finding LoD for performance
7
Object setup Actor Collision bounding box shape
8
Demos Spin – simple motion showing S-C-A and in-game messaging. The empty fires off a message to Bullet that starts it’s motion. Shows Local vs Global motion. Shows animated materials (changing color). Shows use of Mist. Drop – uses physics to drop stuff in place. Demonstrates the collision and timer sensors on cylinder.008 Keyboard – processes keyboard input. Note camera parenting to the player called camera following. Shows keyboard sensor and event processing from the sensor stack, dynamically configuring an actuator (the motion sensor), gates (for level complete), and overlaying scenes.
9
Helpful Hints Actions (like transpose/move) can be either Local to the object’s axis, or Global to the world axis Mass is relevant to collisions; how much one deflects the other is vectored to their relative masses Show console (on Windows: Window->Toggle System Console; Linux start Blender from a console window) to see print() statements.
10
Tips Change the rendering engine in the Info window header to Blender Game-reveals a lot of game options in the menus Code and debug inside Blender for instant feedback Use Code colors Try dir(bpy.game) in a python controller (has to be while game is running) Hover over a UI element to see the API call being made
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.