Hi! i need some help with a camera issue.
Im making a 3rd person game and i want a drag camera orbit thingy.
I have tried MouseOrbitImproved (Author Veli V). but it has a mouse bug.
then i tried this camera orbit on mouse drag(forum), but it has a smoothing thingy
and it is very annoying. so i made like a mix of these two and i got good result but i am not really satisfied by that the camera “bouncing” back when you get to a distance, i want the camera to have a maxdistance, and when it reach the maxdistance it will stay on it, and not “bounce” back.
(Sorry for my grammatical mistakes)
Here is the mix:
using UnityEngine;
using System.Collections;
public class MouseOrbit : MonoBehaviour
{
public Transform target;
public float distance = 5.0f;
public float xSpeed = 120.0f;
public float ySpeed = 120.0f;
public float x = 0.0f;
public float y = 0.0f;
// Use this for initialization
void Start ()
{
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
if(rigidbody)
{
rigidbody.freezeRotation = true;
}
}
// Update is called once per frame
void Update ()
{
if(target)
{
if(Input.GetMouseButton(0))
{
x += xSpeed * Input.GetAxis("Mouse X");
y += ySpeed * Input.GetAxis("Mouse Y");
}
}
Quaternion rotation = Quaternion.Euler (y, x, 0);
//Mouse ScrollWheel
distance = Mathf.Clamp (distance - Input.GetAxis ("Mouse ScrollWheel") * 5, .5f, 15f);
RaycastHit hit;
if(Physics.Linecast (target.position, transform.position, out hit))
{
distance -= hit.distance;
}
Vector3 negDistance = new Vector3 (0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
transform.rotation = rotation;
transform.position = position;
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < 360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}
}