3 - Object Mass

Requirements

Range Engine or UPBGE 2.5b+ is recommended, you can use any version.

The code

We'll be getting and setting an object's mass using the game engine function mass.

Fire up Range and open up text editor. Create a new python script and rename it as whatever you want, I'll be renaming it as code.py just to keep it easy to remember lol.

Import the module, define the owner and get an object's mass. We'll be getting the default cube's mass and setting it to 30 units, if the mass was not 2. So the code looks like this.

import Range
own = Range.logic.getCurrentController().owner
if own.mass != 2:
	own.mass = 2

Duplicate the cube, now your scene must be having two cubes in opposite direction. Like Cube in X: 2.00 and Cube 2 in X: -2.00. Add a plane under both cubes like a see-saw like this.

Cube mass with Range Engine
2 Cubes above the plane

Select the first cube and go to logic editor, add a mouse sensor and add a python controller. Select our code.py script and connect the logic bricks.

Now run the game. If your plane which has two cubes above it has freezed after 2-4 seconds, go to physics setting and turn on No Sleeping. This prevents the object which has phyics running from deactivating the simulation.

Try running the game again. It should look something like this and if it runs as expected that's cool!

Having fun with object's mass

Here is the project file, was written with Range 1.5a