Need Help on how to make an object random rotate...

My goal is I have a Its like a Roulette Wheel. Its going to be used to randomly select something. I need to be able to in the Game Engine have it rotate randomly from 360-1440. In other words they click it and then it rotates either one full rotation or 4 full rotation or somewhere in between that amount needs to be random. In other words I would need lets say rotate X to randomly have either 360-1440 chosen and then have it rotate that much. Is this something that would need a Python Script? I am a programmer/QA by trade but would need to find how to write it and implement it so it can read my object already made in blender. Ideal if I could just use the nodes to do the job without an extra Python script so any one know how to do this? Yes I tried Googling it.

keypress----------------and-------------add 1 to Property
if property min:0 max:?-/

if keypress invert------python
if property!=0--------/

import bge
cont=bge.logic.getCurrentController()
own=cont.owner()
own.applyTorque((0,0,own[‘Property’]),1)
own[‘Property’]=0

Attachments

wheel.blend (442 KB)

As you want to determine the random choice beforehand you can even do that without Python.

Preparation:
Create a turning animation,
ensure it has no end (extrapolation)
ensure a whole number keyframe let the pointer/ball match a slot

Behavior:
Chose a random number and place it in a property.
Play the turn animation in a way that it ends with the random number.

Unfortunately a sudden stop does not look natural. So you need some tricks to look natural.
A) add a brake -> the sudden stop is believable
B) use slow parent -> smooth stop
C) decrease the size of the steps between the played keyframes till the wheel stops.

You can use the random module in python to generate “random” numbers. More specifically it sounds like you want to use random.randint(min, max)

This function will return an integer between the “min” value and the “max” value. So your code may look something like this. (assuming you use the property “rand” on your object.

from bge import logic
import random
min = 360
max = 1440

own = logic.getCurrentController().owner
own['<i><b>rand</b></i>'] = random.randint(min, max)

(UnTested)

Where you change own[‘rand’] to whatever property you want to assign the random number to. You can also change min and max. Then simply attach this script to a python controller :slight_smile:

So then you would follow monster’s steps for the “animation” :slight_smile:

BluePrintRandom, Monster and Kendrick1397 Thanks for the help I should be able to get it to work. Again Thanks.