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

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

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

l'm familiar with how to make collectible 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.

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.

## 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.

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

## Python

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

from bge import logic, events

cont = logic.getCurrentController()
keyboard = logic.keyboard.events

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.

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

• Is applyTorque only accessible via bge? I mean, is it possible to do anything bge can via bpy? I've started learning it, and it seems to me bge exposes other functionalities that I don't need for my animation. Commented Oct 6, 2018 at 2:19
• bpy and bge are completely separate modules. The first is made for blender, the latter is only for the game engine. The functionality from bge is almost always reproducible in bpy. However there is plenty that is not accessible through bge. Commented Oct 10, 2018 at 13:17
• Thank you! In this case, what would be the bpy equivalent to applyTorque? Actually, should I create another question about this? Commented Oct 11, 2018 at 1:02
• @Yamaneko probably a good idea to make a new question. (I do not know off the top of my head). Commented Oct 11, 2018 at 7:29