Question by
MisteriosM · Jan 03, 2017 at 11:07 PM ·
rotationtransformrotaterotate objectworldspace
how do I rotate an object without affecting later rotation?
I am trying to rotate an object using a controller Stick. Unfortunately previous rotations seem to affect the absolute rotation the object is turning in. If I flip it upside down the left and right rotation will be reversed, for example.
I read about Quaternions but I can't understand them.
Sorry for being such a noob, hope you can help.
Here is my code:
public class PlanetSpin : MonoBehaviour
{
public OVRInput.Controller controller;
public float rotationspeed = 15;
// Use this for initialization
void Start()
{
transform.localRotation = Random.rotation;
}
// Update is called once per frame
void Update()
{
Vector2 rStickXYPos = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
float rStickXPos = rStickXYPos.x;
float rStickYPos = rStickXYPos.y;
if (rStickYPos != 0) transform.Rotate(Time.deltaTime * rotationspeed * rStickYPos, 0, 0, Space.World);
if (rStickXPos != 0) transform.Rotate(0,0,Time.deltaTime * rotationspeed * rStickXPos, Space.World);
}
}
Comment