Hi all,
Currently I have an object that after I provide input it rotates 90 degrees in different ways on a global rotation. Unfortunately when I moved it over to iOS I realised that I had not implemented a Time.deltaTime multiplier, so the rotation was slower than it should have been.
Here is the code, its probably terrible.
public class CubeController : MonoBehaviour {
public GameObject cube = null;
public float xRot = 0f;
public float yRot = 0f;
public float zRot = 0f;
public bool imRotating = false;
public int speed = 0;
//Use this for initialization
void Start () {
GameObject.Find("SwipeController").GetComponent<SwipeControl>().SetMethodToCall(MyCallbackMethod);
}
//Update is called once per frame
void Update() {
Transform theCube = cube.GetComponent<Transform>();
if (xRot != 0 || yRot != 0 || zRot != 0)
{
imRotating = true;
}
else
{
imRotating = false;
}
//xRot
if (xRot > 0)
{
theCube.Rotate(-speed, 0, 0, Space.World);
xRot -= speed;
}
if (xRot < 0)
{
theCube.Rotate(speed, 0, 0, Space.World);
xRot += speed;
}
//zRot
if (zRot > 0)
{
theCube.Rotate(0, 0, -speed, Space.World);
zRot -= speed;
}
if (zRot < 0)
{
theCube.Rotate(0, 0, speed, Space.World);
zRot += speed;
}
//yRot
if (yRot > 0)
{
theCube.Rotate(0, -speed, 0, Space.World);
yRot -= speed;
}
if (yRot < 0)
{
theCube.Rotate(0, speed, 0, Space.World);
yRot+=speed;
}
}
public void RotateTopLeft()
{
if (imRotating == false)
{
zRot = 90f;
}
else
{
print("I can't rotate, I'm still rotating");
}
}
public void RotateTopRight()
{
if (imRotating == false)
{
zRot = -90f;
}
else
{
print("I can't rotate, I'm still rotating");
}
}
public void RotateBottomLeft()
{
if (imRotating == false)
{
xRot = -90f;
}
else
{
print("I can't rotate, I'm still rotating");
}
}
public void RotateBottomRight()
{
if (imRotating == false)
{
xRot = 90f;
}
else
{
print("I can't rotate, I'm still rotating");
}
}
In summary, I need the object to rotate to 90 degrees on world rotation on different axis, but I need the speed of the rotation to be consistent over different frame rates. I’ve tried multiplying the speed by Time.deltaTime but it doesn’t seem to work with my script. Any suggestions?
Cheers.