Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Wheel of Fortune slow down wheel

Discussion in 'Project Tiny' started by gattzack, Jun 17, 2019.

  1. gattzack

    gattzack

    Joined:
    May 21, 2017
    Posts:
    13
    I am trying to create a wheel of fortune game and have managed to make the wheel spin and show the correct points. Can someone please help me make the wheel slow down at the last wheel seconds of spinning?

    Code (JavaScript):
    1.         static Spinning: boolean = true;
    2.         static ButtonPressed: boolean = false;
    3.         static newRot: number;
    4.         OnUpdate():void {
    5.             this.world.forEach([ut.Entity, game.Sectors, ut.Core2D.TransformLocalRotation, game.DownTimer],
    6.                 (entity, sect, transform, tim) => {
    7.  
    8.                     if(SpinWheel.ButtonPressed){
    9.                         tim.Timer -= this.scheduler.deltaTime();
    10.  
    11.                         let rot = new Vector3();
    12.  
    13.                         let RandomValue = (Math.random() * 360);
    14.  
    15.                         if(SpinWheel.Spinning){
    16.                             for(var i = 0; i < RandomValue; i++){
    17.                                 rot.z += 1;
    18.                             }
    19.  
    20.                             if(rot.z > 1){
    21.                                 rot.z = Math.round(rot.z/ 5) * 5;
    22.                             }
    23.                             console.log(rot.z);
    24.                         }
    25.  
    26.                         // sect.RotationAngle = rot;
    27.  
    28.                         // sect.CurrentRotation = sect.CurrentRotation.add(sect.RotationAngle);
    29.                      
    30.                         if(tim.Timer >= 0){
    31.                             SpinWheel.newRot = rot.z;
    32.                             SpinWheel.SetRotationFromDegrees(this.world, entity, new Vector3(0,0,1), SpinWheel.newRot);
    33.                         } else if(tim.Timer <= 0){
    34.                             //console.log("Angle : " + rot.z);
    35.                             switch(SpinWheel.newRot){
    36.                                 case 1 :
    37.                                 case 5 :
    38.                                 case 10 :
    39.                                 case 15 :
    40.                                 case 20 :
    41.                                 case 25 :
    42.                                 case 30 :
    43.                                 case 35 :
    44.                                 case 40 :
    45.                                 case 45 :
    46.                                 case 50 :
    47.                                     console.log("Won 60");
    48.                                     ShowValue.OnGainScore1(this.world);
    49.                                     SpinWheel.Spinning = false;
    50.                                     break;
    51.                                 case 55 :
    52.                                 case 60 :
    53.                                 case 65 :
    54.                                 case 70 :
    55.                                 case 75 :
    56.                                 case 80 :
    57.                                 case 85 :
    58.                                 case 90 :
    59.                                 case 95 :
    60.                                 case 100 :
    61.                                     console.log("Won 10");
    62.                                     ShowValue.OnGainScore2(this.world);
    63.                                     SpinWheel.Spinning = false;
    64.                                     break;
    65.                                 case 105 :
    66.                                 case 110 :
    67.                                 case 115 :
    68.                                 case 120 :
    69.                                 case 125 :
    70.                                 case 130 :
    71.                                 case 135 :
    72.                                 case 140 :
    73.                                 case 145 :
    74.                                 case 150 :
    75.                                     console.log("Won 50");
    76.                                     ShowValue.OnGainScore3(this.world);
    77.                                     SpinWheel.Spinning = false;
    78.                                     break;
    79.                                 case 155:
    80.                                 case 160 :
    81.                                 case 165 :
    82.                                 case 170 :
    83.                                 case 175 :
    84.                                 case 180 :
    85.                                 case 185 :
    86.                                 case 190 :
    87.                                 case 195 :
    88.                                 case 200 :
    89.                                 case 205 :
    90.                                     console.log("Won 20");
    91.                                     ShowValue.OnGainScore4(this.world);
    92.                                     SpinWheel.Spinning = false;
    93.                                     break;
    94.                                 case 210:
    95.                                 case 215 :
    96.                                 case 220 :
    97.                                 case 230 :
    98.                                 case 235 :
    99.                                 case 240 :
    100.                                 case 245 :
    101.                                 case 250 :
    102.                                 case 255 :
    103.                                     console.log("Won 30");
    104.                                     ShowValue.OnGainScore5(this.world);
    105.                                     SpinWheel.Spinning = false;
    106.                                     break;
    107.                                 case 260:
    108.                                 case 265 :
    109.                                 case 270 :
    110.                                 case 275 :
    111.                                 case 280 :
    112.                                 case 285 :
    113.                                 case 290 :
    114.                                 case 295 :
    115.                                 case 300 :
    116.                                     console.log("Won 80");
    117.                                     ShowValue.OnGainScore6(this.world);
    118.                                     SpinWheel.Spinning = false;
    119.                                     break;
    120.                                 case 305:
    121.                                 case 310 :
    122.                                 case 315 :
    123.                                 case 320 :
    124.                                 case 325 :
    125.                                 case 330 :
    126.                                 case 335 :
    127.                                 case 340 :
    128.                                 case 345 :
    129.                                 case 350 :
    130.                                 case 355 :
    131.                                 case 360 :
    132.                                     console.log("Won 40");
    133.                                     ShowValue.OnGainScore7(this.world);
    134.                                     SpinWheel.Spinning = false;
    135.                                     break;
    136.                             }
    137.                          
    138.                             return;
    139.                         }
    140.                     }
    141.  
    142.                 });
    143.         }
    144.  
    145.         static Spin(world : ut.World):void{
    146.          
    147.         }
    148.  
    149.         static SetRotationFromDegrees(world: ut.World, entity: ut.Entity, axis: Vector3, degrees: number) {
    150.             if (!world.hasComponent(entity, ut.Core2D.TransformLocalRotation)) {
    151.                 console.error("Provided entity does not contain the ut.Core2D.TransformLocalRotation component.");
    152.                 return null;
    153.             }
    154.        
    155.             let rot = world.getComponentData(entity, ut.Core2D.TransformLocalRotation);
    156.             rot.rotation.setFromAxisAngle(axis, (degrees / 180) * Math.PI);
    157.             world.setComponentData(entity, rot);
    158.  
    159.         }
    160.  
    161.         static PushSpinBool(Pressed: boolean){
    162.             if(Pressed){
    163.                 this.ButtonPressed = true;
    164.             }
    165.         }
     
    Last edited: Jun 17, 2019
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Should be simple when time < 1f multiply the rotation by the remaining time value.