- Home /
Rotate camera smooth on touch
Hello,
I'am working on a camera script which rotates on touch. But the problem is, the movement is far from smooth, i'am using the following code:
var target : Transform;
var distance = 10.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
var xsign = 1;
var gasPedal : GUITexture;
var brakePedal : GUITexture;
var transmissionControl : GUITexture;
var steeringWheel : TouchSteering;
var hitGUI : boolean;
var touchPosition : Vector2;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
function Update() {
var forward = transform.TransformDirection(Vector3.up);
var forward2 = target.transform.TransformDirection(Vector3.up);
if (Vector3.Dot(forward,forward2) < 0)
xsign = -1;
else
xsign = 1;
for (var touch : Touch in Input.touches) {
touchPosition = touch.deltaPosition * Time.deltaTime / touch.deltaTime;
if (touch.phase == TouchPhase.Moved && !guiHit()) {
x += xsign * touchPosition.x * xSpeed * 0.02;
y -= touchPosition.y * ySpeed * 0.02;
y = Mathf.Clamp(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
}
Fluxxi
Comment
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Camera in fixed position which rotates with player. 0 Answers
Dragging Camera based on Touch 0 Answers
camera smooth stop (continuously sliding), on touch end 0 Answers
MiniMap with player and object icons 1 Answer