# Tps Mouse Orbit Multi Views When Make Aim

hey guys i need help how change distance in camera orbit when press mouse 2 becouse it’s tps game but i want aim fps so i want change distance when press mouse 2 from 2.0 for 0.0

Mouse Orbit code here

``````var target : Transform;
var distance = 2.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;

@script AddComponentMenu("Camera-Control/Mouse Orbit")

function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;

// Make the rigid body not change rotation
if (GetComponent.<Rigidbody>())
GetComponent.<Rigidbody>().freezeRotation = true;
}

function LateUpdate () {
if (target) {
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;

y = ClampAngle(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;
}
}

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);
}
``````

hey . any help?

there are a few ways to approach this issue. the easiest way to do this is to make 2 empty game objects that are children of your character. one placed in the head and one over the shoulder. then when you take your inputs look for your aim button. if it is down or held (i am not sure if you want toggle or held) switch which position to use. it also looks much better if you lerp to that position. it gives that camera zooming feel to the motion.
another way is to use an offset for each FPS and TPS and do the same. basically this is usually easier to do from the player. placing the camera script on the player and just have a variable for the camera. when the button is held the camera finds a position by calculating the players position and the offset using the transform.forward and transform.right. once you have found this position just lerp to it using a smoothing factor and time.deltatime.
the first way is easier and the second is more resource friendly.

``````    public Vector3 tpsOffset;
public Vector3 fpsOffset;
public float speed;

private Transform target;

void Start()
{
target = GetComponentInParent<Transform>();
}

void Update()
{
Vector3 targetPosition = new Vector3();

if (Input.GetAxis("Fire2") > 0f)
targetPosition = fpsOffset;
else
targetPosition = tpsOffset;

transform.localPosition = Vector3.Lerp(transform.localPosition, targetPosition, speed * Time.deltaTime);
}
``````

I ran this on the third person character in the standard assets. Just attach this to your camera, make the camera a child of the player, and adjust the offset values in the inspector during run time. The speed value will make the camera move more quickly to the right spot. All three public variables are very much up to taste. One note. The TPS character in standard assets does not like backing up with this setup. That is because it spins the character rather than moving the character backwards. You will need to mod the code to get that working but most TPS over the shoulder games don’t function like that. The asset is designed for an independent camera, TPS top down style like MGS or Diablo cameras.