5
$\begingroup$

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.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

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

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.
Logic bricks for script

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

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Yamaneko
    Oct 6, 2018 at 2:19
  • 1
    $\begingroup$ 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. $\endgroup$
    – David
    Oct 10, 2018 at 13:17
  • $\begingroup$ Thank you! In this case, what would be the bpy equivalent to applyTorque? Actually, should I create another question about this? $\endgroup$
    – Yamaneko
    Oct 11, 2018 at 1:02
  • $\begingroup$ @Yamaneko probably a good idea to make a new question. (I do not know off the top of my head). $\endgroup$
    – David
    Oct 11, 2018 at 7:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .