- Home /
Camera Rotation Probleme with iPhone
hello, I had a little trouble about the manipulation in touch iphone. I want to move the camera left, right, top and bottom limited by touching any area of the ecranet I can not do: (help please: ( I wanted to be rotated in Prince of Persia Warrior Within in this video at 1:48 (Prince Of persia video's Link) sorry for my English ..
With my code, the camera rotation is very bad. This is the code:
var xOffset : float; var yOffset : float; var target : Transform; var distance = 10.0; var height = 5.0; var speed = 5.0; var yMinLimit = -20; var yMaxLimit = 50; var xSpeed = 250.0; var ySpeed = 125.0;
private var lastY =0.0; private var lastX = 0.0; private var gui : GUITexture;
private var x = 0.0; private var y = 0.0;
function Start () { var angles = transform.eulerAngles; x = angles.y; y = angles.x; }
function Update(){ var position = transform.rotation Vector3(0.0, height, -distance) + target.position; transform.position = position; for (var i=0; i< iPhoneInput.touchCount; i++){ var touch0 : iPhoneTouch=iPhoneInput.touches[0]; if(touch0.phase == iPhoneTouchPhase.Moved ){ x = touch0.deltaPosition.x / xOffset xSpeed 0.02; y = touch0.deltaPosition.y / yOffset ySpeed * 0.02;
}
} } function LateUpdate(){ var rotation = Quaternion.Euler(y, x, 0);
y = ClampAngle(y, yMinLimit, yMaxLimit);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * speed);
} static function ClampAngle (angle : float, min : float, max : float) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp (angle, min, max); }