Using python you can do more advanced stuff. We'll looking at the game engine's transforming functions.
Range Engine 1.2+ or UPBGE 2.5b+
localPosition, localOrientation and localScale
worldPosition, worldOrientation and worldScale
If you're wondering what were those localPosition, worldOrientation, etc, they are noting but functions used to transform the objects using python. With this you can have control of objects and move, rotate and scale them in global and local axis.
#explanation goes here for world
exp for local
I hope you understood what local and world axis mean, now let's jump to python code. Open up the Text Editor (which is opened be default in Range and UPBGE). If it's not there, change the editor type to Text Editor. We'll be now changing the position of our default cube in world axis. let's import the Range module and get our python controller and owner like so.
import Range
own = Range.logic.getCurrentController()
And then we bring the function worldPosition, and set the values to [3,5,9] something like this: worldPosition = [3,5,9]. So the full code looks like this
import Range
own = Range.logic.getCurrentController()
own.worldPosition = [3,5,9]
Remeber, you gotta put own before almost any functions so the game engine know which object to move, or it won't move any objects.
Bring a keyboard sensor and a Python controller. Select the script where we did all those moving the cube thing.
Connect the bricks and run the game. Press the key which you assigned for the keyboard sensor and then the cube moves!
Now, let's try moving the cube in local axis. Rotate the cube in any degrees and replace the worldPosition with localPosition.
You may wonder "wait why isnt my local position changing?" The problem with that is... your object's rotation needs to be relative to the parent object. Like if your parent object's orientation is [23,45,90] and if you use localPosition on your child object whose rotation is [23,45,90] too, the changed location will be in local axis.
The bricks was setup like this: Always sensor <---------> Python controller.
You can also use applyMovement with an always sensor having true level triggering turned off. So the code looks like this.
import Range
own = Range.logic.getCurrentController()
own.applyMovement([3,5,9], True)
We're applying movement to a certain vector in local axis. You can use 0,1 instead of True, False. 0 = False, and 1 = True. Btw here is the project file.