So i've been trying to implement a roulette with 8 sections and to make the roulette turn to the pre-defined result. (ex. if I enter 3, the roulette turns for 3 times and slows down in number 3). but I've been not able to make the roulette slow down AND land on 3. I tried roulette to slow down, but it slows down with a given negative acceleration.. and if I land on 3, it automatically stops at 3. Any idea how to implement these kind of game?
You can do it manually by controlling the angle and having a static rotation rate. Then just change the angle by the rotation rate every tick and when you want to slow it down, reduce the rotation rate every few seconds or so until it is 0. At that point you just need to fiddle with it until you initiate the slow down at the correct time.
Hey sherlykim
I am also interested in this solution. Could you get this to work? I need to produce a roulette that stops in pre-defined places.
Develop games in your browser. Powerful, performant & highly capable.
I'm no expert but here's how I would do it:
First of all, confirm that the physics engine is deterministic: If the initial angle, ball speed, roulette position and roulette rotation speed is the same, will it always lead to the same final result? Especially on different platforms? If so, then continue on. If not, then this solution won't work. I'm actually new to Construct 2 and don't know how its physics engine operates.
Having the program go on a continual loop of trying random ball angles, ball speeds and roulette starting positions; then marking down which number the ball ends up in. Leave this running for a few hours, and when you return, you'll have a list of initial settings tied with which end number they'll produce. This means that for every number on the roulette wheel you should have a couple of initial settings that you know will produce that number.
So now it's simple, whenever you want to produce a given number on the wheel, you just randomly choose one of the initial setting that you know will produce that number.
Just remember: Any changes to the physics engine may make you have to do the whole thing again. Also, double check that different platforms won't run the physics engine differently. Sometimes floating numbers are dealt with differently by platform.
Hey — Thanks for the help but unfortunately it's very confuse to me. In my case, I am just wanting a simple roulette with 6 numbers only ("game of life" kind). so, I believe that the solution is much more simple than that.
Here's one way. Give your spinner Sprite a variable and call it 'speed'.
Then add this event:
Speed>0
--- add -50*dt to speed
--- rotate self.speed*dt degrees clockwise
That makes the spinner Sprite slow down. Now all that's left is to change the initial speed so it stops at a certain spot. The equation for that is:
Speed=sqrt(2*decceleration*distance)
In the event above deceleration is 50. So if you wanted the spinner to spin twice and land on 90 degrees you'd do this:
Start of layout
--- set speed to sqrt(2*50*(360*2+90))
Or in the case of always landing on one of six positions you could do:
On space pressed
Speed <= 0
--- set speed to sqrt(2*50*(360+int(random(6))*60))
Hey R0J0hound
Sorry about the delay and thanks by the help.
I follow your instructions but something wrong happened. The spinner does not stop.
Some questions:
It doesn't use a behavior at all. Here's a working example of the idea:
https://dl.dropboxusercontent.com/u/542 ... ette2.capx
It doesn't use a behavior at all. Here's a working example of the idea: https://dl.dropboxusercontent.com/u/542 ... ette2.capx
This is very cool. Thanks man. I fixed the first script and it works (with no behavior)
What I need to do if I want that spinner starts with more speed?
How I know when the spinner stop? I have checked and it stops with -0.(some numbers) of speed. Why it is not zero?
I need to manage the spinner to stop where I want. It starts in 0 and goes to 45/108/165/226/283/340 degrees.
You probably just want the spinner to slow down and when it stops just check if the angle is close to one of those.
For example here is an example if there are four values on the wheel:
+-----------------+ | mouse: on click | spinner: set speed to random(100, 400) +-----------------+ +------------------+ | spinner: speed>0 | spinner: subtract 100*dt from speed | | spinner: rotate self.speed*dt degrees clockwise +------------------+ +------------------+ | spinner: speed<0 | spinner: speed set speed to 0 +------------------+ +---------------------------------------+ | spinner: angle is 45 degrees from 0 | add 10 to score +---------------------------------------+ +---------------------------------------+ | spinner: angle is 45 degrees from 90 | add 50 to score +---------------------------------------+ +---------------------------------------+ | spinner: angle is 45 degrees from 180 | add 1337 to score +---------------------------------------+ +---------------------------------------+ | spinner: angle is 45 degrees from 270 | add 123456789 to score +---------------------------------------+[/code:3y93chdi] So in other words it's not necessary to know where it will stop beforehand, you just check the angle when it stops. There I checked the angle with the "is within angle" condition but the "is between angles" could be used too. And in relation to your questions about my capx above: To make it start with more speed just set the start speed higher in the click event. The spinner is stopped when the speed is less than or equal to 0. It's not zero because we can only calculate speed per frame, and seldom will the speed end on 0 at exactly the frame time, so it overshoots slightly.
this is very useful, thanks for sharing.
Very nice. Thanks a lot.
In my case, I need that the spinner stops in pre defined places, following a sequence that could be different each time: 1,3,5,4,6,2,6,6,3,1 or 4,2,5,4,1,6,3,1,3,2 or 6,1,4,2,3,5,2,2,4,1 or ...
Is it possible?
Braus
Sure, why not? In the capx it calculates the initial speed so it rotates n degrees. It's done when the speed is >= to 0.
So you'd either figure out the number of degrees from any position to any other, or find a formula that can do that.
Braus Sure, why not? In the capx it calculates the initial speed so it rotates n degrees. It's done when the speed is >= to 0. So you'd either figure out the number of degrees from any position to any other, or find a formula that can do that.
I got it. I just need to fix an issue with the area corresponding to the place 1 (all the restante are okay). How to check if the spinner is over this place if the first angle of this area starts at 330 degrees and finish at 30 degrees. I tried "within 60 of 30" but it nor worked.
Other question:
If I use sqrt(2*50*(360+int(random(6))*60)) I cannot apply more speed at the beginning?
"within 60 of 30" would mean 330 to 90, or 60 degrees in each direction from 30. So it probably is easier for you to just use the "is between angles" condition instead.
I don't understand your last question. The equation is:
speed = sqrt(2*deceleration*degreesToMove)
It calculates the speed needed so when using a certain deceleration it will stop after rotating degreesToMove degrees. The speed will be higher for higher values of deceleration and degreesToMove.