I'm trying to make a boost power up for my video game but I'm terrible at Python and couldn't do it even if my life depended on it. :| Anyway, here's my setup:

I need it so that:

  1. The default velocity_max for my object is 50.
  2. When the space bar is pressed AND a game property named Boost is greater than 0, change velocity_max to 70.
  3. (The property Boost will count down)
  4. Once Boost reaches 0 or less, the velocity_max will change back to 50, and can only change back to 70 when (as in #2) spacebar is pressed AND Boost becomes greater than 0 again.

Thanks again.


1 Answer 1

import bge

controller = bge.logic.getCurrentController()
owner = controller.owner
boost = owner["boost"]

if controller.sensors["boost"].positive and controller.sensors["is boostable"].positive:
    owner.linVelocityMax = 7
    owner.linVelocityMax = 2 

requires two sensors:

  • "boost" -> requests to boost

  • "is boostable" -> checks if boosting is available

enter image description here

this does not include counting.

Counting needs a frequent trigger otherwise you count how many times boost was requested, not how long it took. I suggest to add an always sensor with [True Level Triggering]. This way it constantly triggers the controller. The controller is simply an AND controller. There is not need to execute Python all the time.

enter image description here

For better reading this this is placed at a different state. Make sure both states are enabled when starting the game.


I suggest to call the property something like "boost energy" as I guess it should represent some sort of consumed element.

The above system (as you described) is a very easy and simple system assuming t the amount of consumed "boost" is constant. If that is not the case you can indeed create a system that takes away a part of the boost value (immediately reducing the property value) and results in a velocity change. This requires the code to run at each single frame.

I'm not sure if changing the max-velocity can be considered as "boost". The max-velocity applies to all physics calculations inclusive falling.

  • $\begingroup$ This is great! Works like a charm. On a similar note, where did you learn how to code in Python, specifically with the commands and functions Blender uses? $\endgroup$ Jan 23, 2017 at 18:51
  • 1
    $\begingroup$ As funny as it sounds - with the BGE. That was the reason to use Python. (It also helps that I'm working in IT). $\endgroup$
    – Monster
    Jan 24, 2017 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .