- Home /
translating a touchDeltaPosition from the y axis to z axis
Hi - I'm using unity in conjunction with an ipad to throw an object based on a user dragging their finger across the screen. But when a user moves their finger vertically on the screen, I want that to translate to a movement of the object on the Z axis instead of the Y. How would I accomplish this? Here's my code.
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector3 = Input.GetTouch(0).deltaPosition;
// Apply force to the object
newObject.rigidbody.AddForce(touchDeltaPosition * force);
}
Comment
Best Answer
Answer by DaveA · Jul 11, 2011 at 08:45 PM
You have to swizzle the y and z components
var theForce : Vector3 = new Vector3 (touchDeltaPosition.x, 0, touchDeltaPosition.y);
newObject.rigidbody.AddForce(theForce * force);