Basic 3-Axis Rotation via Touch

Hi,

I’m working on my first small project, trying to understand scripting.

Could someone help me understand how to put together a script that will allow me to rotate/spin a cube via a touch/swipe (iOS) around the center 0,0,0 axis? I’m using C#, opposed to java, which is where I’ve found most of the tutorials online. Any help would be most appreciated.

EDIT:

I figured out something that’s helped me a lot (renman3000 gave me an idea of what to look for). I’m using the code below, but when i swipe up/down it’s causing a rotation on the x axis, instead of y, and a sideways swipe causes rotation on the y axis.

Thoughts?

publicclassRotate : MonoBehaviour {

publicfloatspeed = 0.1F;
voidUpdate() {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Rotate(touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);
}
}
}

If you want to access each access, each axis, I would consider swipe up, x axis, swipe left y axis, and diagonal z. I would alter the axis rotation values by localEulerAngles.

So, I would look up touch input, or, you could use mouse for now. On deltaPositon (change in touch pos) ask what the change was. Left, right. Up, down. Diagonal. Based on this and the factor, amount of change, how fast the swipe, adjust the appropriate axis.

Thanks for your help, though I found something a little simpler for me to understand (i’m only about 8 hours into learning Unity/C#). Any thoughts on why the code above would be confusing the two axis?

I am not sure what you are referencing.