- Home /
Question by
realvasion · Dec 04, 2017 at 04:07 PM ·
rotate objectdraggingwheel
Adding Accelerating to a Wheel of fortune
Basically I want to create a wheel of fortune where user turn the wheel by actually clicking and dragging the wheel (like real wheel of fortune). The problem is I don’t know how to add an acceleration to it base on how fast the user drag the wheel and also adding friction to slow it down. something similar to this: https://youtu.be/x6wOjk5AwZQ?t=3m34s
here is my code: using UnityEngine; using System.Collections;
public class RotateWheel : MonoBehaviour
{
private float baseAngle = 0.0f;
void OnMouseDown()
{
var dir = Camera.main.WorldToScreenPoint(transform.position);
dir = Input.mousePosition - dir;
baseAngle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
baseAngle -= Mathf.Atan2(transform.right.y, transform.right.x) * Mathf.Rad2Deg;
}
void OnMouseDrag()
{
var dir = Camera.main.WorldToScreenPoint(transform.position);
dir = Input.mousePosition - dir;
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - baseAngle;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}
any help is much appreciated :)
Comment