- Home /
Camera rotation - button emulation
Hi all~
I found this script earlier (see below) and would like to implement the camera rotation effect on a button - but preferably when the user moves their cursor to the edges of the screen.
p.s. I am noob with scripting
Thanks
var target : Transform;
var edgeBorder = 0.1;
var horizontalSpeed = 360.0;
var verticalSpeed = 120.0;
var minVertical = 20.0;
var maxVertical = 90.0;
private var x = 0.0;
private var y = 0.0;
private var distance = 0.0;
function Start()
{
x = transform.eulerAngles.y;
y = transform.eulerAngles.x;
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;
ret
``urn Mathf.Clamp (angle, min, max);
}
Comment
Your answer
Follow this Question
Related Questions
Camera Rotation 1 Answer
Attach image to button 1 Answer
Need help for player rotation and camera rotation 0 Answers
How to restrict rotation properly 2 Answers