So I am making a space game and I wrote a script for the camera to be in one position, and when the scroll wheel is pushed down, you can orbit the camera around the ship. The problem I am having is getting the camera to go back behind the ship. This is my script:
float rspeed = 2.5F;
bool move = false;
public Transform target;
public Transform camsp;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButton(2))
{
float rotx = Input.GetAxis("Mouse X") * rspeed;
float roty = Input.GetAxis("Mouse Y") * rspeed;
transform.RotateAround(target.position, target.up, rotx);
transform.RotateAround(target.position, target.right, roty);
}
if(Input.GetMouseButtonUp(2))
{
//sp = transform.position;
move = true;
}
if (move == true)
{
transform.position = new Vector3(Mathf.Lerp(transform.position.x, camsp.transform.position.x, Time.deltaTime), Mathf.Lerp(transform.position.y, camsp.transform.position.y, Time.deltaTime), Mathf.Lerp(transform.position.z, camsp.transform.position.z, Time.deltaTime));
transform.LookAt(target);
}
I don’t know how to stop this. I tried this:
if(transform.position == camsp.position)
{
move = false;
}
but it doens’t work. any ideas how to fix this?