Показаны сообщения с ярлыком js. Показать все сообщения
Показаны сообщения с ярлыком js. Показать все сообщения

четверг, 19 апреля 2012 г.

Свободная камера


#pragma strict
var lookSpeed = 15.0;
var moveSpeed = 15.0;

var rotationX = 0.0;
var rotationY = 0.0;

function Update ()
{
    rotationX += Input.GetAxis("Mouse X")*lookSpeed;
    rotationY += Input.GetAxis("Mouse Y")*lookSpeed;
    rotationY = Mathf.Clamp (rotationY, -90, 90);
    
    transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
    transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
    
    transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
    transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
}

среда, 4 апреля 2012 г.

Вращение камеры вокруг объекта


var target : Transform; //What to rotate around
var distance = 5.0; //How far away to orbit
var xSpeed = 125.0; //X sensitivity
var ySpeed = 50.0; //Y sensitivity

private var x = 0.0; //Angle of the y rotation?
private var y = 0.0; //Angle of the x rotation?

@script AddComponentMenu("Scripts/Mouse Orbit") //Add to menu

function Start() {Run this once at the start
    //Initialize the angles
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;
}

function LateUpdate() { //Every frame, do this as late as you can
    if (target) {//There's a target
        //Change the angles by the mouse movement
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;

        //Rotate the camera to those angles 
        var rotation = Quaternion.Euler(y, x, 0);
        transform.rotation = rotation;

        //Move the camera to look at the target
        var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        transform.position = position;
    }
}