Blender game: How you can I make a ball roll while moving?

by Paulius   Last Updated July 24, 2015 13:06 PM - source

I'm making a game where a robotic ball moves, collect objects and pass obstacles, and my question is :

  • how can I make the ball roll while it is moving ?

l'm familiar with how to make collectable game objects and with in game animation but l just don't known how to make a ball roll while moving. l understand how to program with the logic bricks.

Answers 1

Torque causes rotational motion; therefore, applying torque will make the ball roll. This can be done with logic bricks or with python.

For both ways start out on the ball's physics, set Physics Type to Ridge Body and adjust the radius to the the size of the ball.
Physics settings

Logic bricks

Then on the ball add a Motion actuator. On the motion actuator, uncheck use local torque (the L on the right) and set the torque on one of the axes.

Motion actuator

Connect keyboard sensors to the motion actuators with corresponding torque for the axis.

Complete logic setup


Using python, create a text block and add this script.

from bge import logic, events

cont = logic.getCurrentController()
keyboard =

x, y = 0, 0

if keyboard[events.UPARROWKEY]: x += 1
if keyboard[events.DOWNARROWKEY]: x -= 1
if keyboard[events.LEFTARROWKEY]: y += 1
if keyboard[events.RIGHTARROWKEY]: y -= 1

cont.owner.applyTorque((x, y, 0))

Then connect an Always sensor to a Python controller and activate TRUE level triggering.
Logic bricks for script

The logic bricks or script will roll the ball. *This is a monkey shaped ball.*
Ball rolling around

July 25, 2015 16:46 PM

Related Questions

Bullets fall with gravity issue

Updated April 11, 2015 00:06 AM

How to make a property control velocity?

Updated June 10, 2015 10:06 AM

Car Physics In the BGE

Updated December 24, 2017 21:15 PM

Directional gravity for irregular shapes

Updated April 29, 2015 02:06 AM