Search Unity

Creating a 2D "Wheel of Fortune"

Discussion in 'Physics' started by Mikeysee, Feb 4, 2015.

  1. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Hi Guys,

    Im having issues trying to create a 2D wheel of fortune, see the below video for the problem:



    Notice that the "Clacker" gets stuck and pulls away from its hinge point.

    To simulate this I am using a hinge joint and two sping joints on the clacker and the wheel contains a number of pegs which are non-kinematic circle colliders.

    I have also added a distance joint to the clacker to try and force it to stay where it is but to no avail.

    Can anyone think of a better way of doing this?
     
  2. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Scratch that. I worked it out.

    Incase anyone wants to do something simmilar, make sure the "pegs" dont have a rigidbody an give the wheel a hinge joint
     
  3. Miyavi

    Miyavi

    Joined:
    Mar 10, 2012
    Posts:
    58
    Hey, would it be possible for you to post the project? (Or the spinning wheel part, for the matter).

    I'm trying to do one, too, but I'm hitting a wall in several ways :x
     
  4. subzer0

    subzer0

    Joined:
    Dec 10, 2010
    Posts:
    94
    @Mikeysee I am making a similar spinning wheel and the spinning worked, but my problem is that how can I know what item was chosen at the end ?
    Can you tell me how to do it ?:)

    EDIT: Nevermind. I found a way to do it. Just add a triggered 2d collider ( I added a polygon collider) on an empty gameobject and put it above each item. And after the spinning is finished, detect to which collider the clacker has collided.
     
    Last edited: Feb 1, 2016
  5. cb4nd17

    cb4nd17

    Joined:
    Jun 16, 2017
    Posts:
    4
    Hi Guy's I'm trying to get the spinner work with a button like yours on click but can't seem to get it. I'm using a code that I got from the appguruz. here is the code

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class SpinWheel : MonoBehaviour
    {
    public List<int> prize;
    public List<AnimationCurve> animationCurves;

    private bool spinning;
    private float anglePerItem;
    private int randomTime;
    private int itemNumber;

    void Start(){
    spinning = false;
    anglePerItem = 360/prize.Count;
    }

    void Update ()
    {
    if (Input.GetKeyDown (KeyCode.Space) && !spinning) {

    randomTime = Random.Range (1, 4);
    itemNumber = Random.Range (0, prize.Count);
    float maxAngle = 360 * randomTime + (itemNumber * anglePerItem);

    StartCoroutine (SpinTheWheel (5 * randomTime, maxAngle));
    }
    }

    IEnumerator SpinTheWheel (float time, float maxAngle)
    {
    spinning = true;

    float timer = 0.0f;
    float startAngle = transform.eulerAngles.z;
    maxAngle = maxAngle - startAngle;

    int animationCurveNumber = Random.Range (0, animationCurves.Count);
    Debug.Log ("Animation Curve No. : " + animationCurveNumber);

    while (timer < time) {
    //to calculate rotation
    float angle = maxAngle * animationCurves [animationCurveNumber].Evaluate (timer / time) ;
    transform.eulerAngles = new Vector3 (0.0f, 0.0f, angle + startAngle);
    timer += Time.deltaTime;
    yield return 0;
    }

    transform.eulerAngles = new Vector3 (0.0f, 0.0f, maxAngle + startAngle);
    spinning = false;

    Debug.Log ("Prize: " + prize [itemNumber]);//use prize[itemNumnber] as per requirement
    }
    }
     
  6. cb4nd17

    cb4nd17

    Joined:
    Jun 16, 2017
    Posts:
    4
    any Ideas, also I would like to fill the wheel with images when clicked on and make it a multiplayer game.
     
  7. cb4nd17

    cb4nd17

    Joined:
    Jun 16, 2017
    Posts:
    4
  8. cb4nd17

    cb4nd17

    Joined:
    Jun 16, 2017
    Posts:
    4
    Sorry to reply so late. Has everyone solve their own issue or do you need some of my help with something?
     
  9. miniflipgames

    miniflipgames

    Joined:
    Sep 25, 2017
    Posts:
    1
    can i get the code for this sence