Hi, I’m trying to make a wheel of fortune for an android game.
In Unity editor the rotation is smooth, but not on mobile. I don’t have much experience with programming so I’m getting really desperate. I changed Fixed Timestep
to 0,0166
, I tried FixedUpadate
and Update
, but still the rotation is not smooth enough.
using UnityEngine;
public class Ruleta : MonoBehaviour
{
public float RotatePower;
public float StopPower;
private Rigidbody2D rbody;
int inRotate;
public float angle;
private void Start()
{
rbody = GetComponent<Rigidbody2D>();
}
float t;
private void FixedUpdate()
{
angle = transform.eulerAngles.z;
if (rbody.angularVelocity > 0)
{
rbody.angularVelocity -= StopPower * Time.fixedDeltaTime;
rbody.angularVelocity = Mathf.Clamp(rbody.angularVelocity, 0, 1440);
}
if (rbody.angularVelocity == 0 && inRotate == 1)
{
t += 1 * Time.fixedDeltaTime;
if (t >= 0.5f)
{
inRotate = 0;
t = 0;
}
}
}
public void SelectRandomPower()
{
float randomPowerIndex = Random.RandomRange((float)679.4788, (float)791.3574);
RotatePower = randomPowerIndex;
}
public void Rotate()
{
if (inRotate == 0)
{
SelectRandomPower();
rbody.AddTorque(RotatePower);
inRotate = 1;
}
}
}