- Home /
camera rotate with limitation around x and y axis by using touch
hello there i have recently developed an app for both mac and pc, and now i am trying to modify the same app for mobile usage.
my question is this: by using a transform variable i set an object to be in the middle right in front of the camera. there are no limits for x rotation, but a 85 degree limitation for the y axis for the camera. therefore my camera orbits x by 360 and 85 degrees on y from the facing side of the object, so i can not see the bottom of the object which is what i intend to do with touch as well. the whole code is shown below:
var target : Transform;
var edgeBorder = 0.1;
var horizontalSpeed = 360.0;
var verticalSpeed = 120.0;
var maxVertical = 85.0;
var minVertical = 0;
private var x = 0.0;
private var y = 0.0;
private var distance = 0.0;
function Start()
{
y = transform.eulerAngles.x;
x = transform.eulerAngles.y;
distance = (transform.position - target.position).magnitude;
}
function LateUpdate()
{
var dt = Time.deltaTime;
x += Input.GetAxis("Horizontal") * horizontalSpeed * dt;
y -= Input.GetAxis("Vertical") * verticalSpeed * dt;
y = ClampAngle(y, minVertical, maxVertical);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
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);
}
how is it possible to use or edit this to something similar by using touch for mobile? thanks a bunch in advance...
Your answer
Follow this Question
Related Questions
Cannot get GUIUtility.RotateAroundPivot working 1 Answer
rotate object to touch position 1 Answer
Rotating Joystick on Touch 0 Answers
Remove Y-axis clamp from Tap to Move, Drag to Look Script 0 Answers