I'm making a game where a robotic ball moves, collect objects and pass obstacles, and my question is :
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.
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.
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.
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.
The logic bricks or script will roll the ball. *This is a monkey shaped ball.*