How to make a Homeworld Style Camera.

I'd like to know how I would get this to work correctly. For those who have played Homeworld 1 or pretty much any space RTS you are able to move the camera around by holding the right mouse button and then moving the mouse. You are also able to scroll in and out using the scroll wheel. I've seen some things like this around here but they have all mainly been for Land based RTS's and haven't given me the desired result even with a bit of tinkering. Any Help is appreciated.

This script will allow you to assign (using the Input Manager), two axes for Camera Movement, one for "Camera Enable" (which, in your case, should be the right mouse button), as well as camera rotation and a "Camera Rotation Enabler" (which, for my game, was the middle mouse button).

So the end result of this script, after all the input axes are setup correctly, is:

Hold RMB to drag and move the camera around. Hold MMB (Scroll Wheel) and drag left or right to rotate the camera around.

I don't remember what the values were inside of the Input Manager (and I don't think I have the project anymore), so you'll need to figure that out yourself by reading this script and assigning values to the functions noted in the script. This will NOT work by just copy-pasting it!

Input Values that need to be added:

  • Camera X - Button for left/right camera (like the keyboard arrows)
  • Camera Y - Button for up/down (like the keyboard arrows)
  • Move Camera Enabler - Button for enabling camera mouse movement (like the RMB)
  • Camera X Mouse - Mouse X Axis
  • Camera Y Mouse - Mouse Y Axis
  • Camera Rotation - Middle mouse button (typically mouse button 1 or 2).
  • Camera Zoom - Mouse Scrollwheel for zooming in and out (Mouse Axis 3).

using UnityEngine;
using System;

[AddComponentMenu("Camera Control/Smooth Follow")]
class SmoothFollow : MonoBehaviour
{
    public float CameraMoveSpeed = 60;
    public float CameraMoveMouse = 40;
    public float CameraZoomSpeed = 30;
    public float CameraRotateSpeed = 30;
    public float Camera = 4;

    const float CameraMax = 50;
    const float CameraMin = 15;

    void LateUpdate()
    {
        if (hasInput())
        {
            float thiseulerX = transform.rotation.eulerAngles.x;
            transform.rotation = Quaternion.Euler(0, transform.eulerAngles.y, transform.eulerAngles.z);
            if (Input.GetAxis("Camera X") > 0)
            {
                transform.Translate(Vector3.forward * Time.deltaTime * CameraMoveSpeed);
            }
            if (Input.GetAxis("Camera X") < 0)
            {
                transform.Translate(Vector3.back * Time.deltaTime * CameraMoveSpeed);
            }
            if (Input.GetAxis("Camera Rotation") == 0)
            {
                if (Input.GetAxis("Camera Y") > 0)
                {
                    transform.Translate(Vector3.right * Time.deltaTime * CameraMoveSpeed);
                }
                if (Input.GetAxis("Camera Y") < 0)
                {
                    transform.Translate(Vector3.left * Time.deltaTime * CameraMoveSpeed);
                }
            }

            if (Input.GetAxis("Move Camera Enabler") != 0)
            {
                Screen.lockCursor = true;
                if (Input.GetAxis("Camera X Mouse") != 0)
                {
                    transform.Translate(Vector3.forward * Time.deltaTime * CameraMoveMouse * Input.GetAxis("Camera X Mouse"), Space.Self);
                }
                if (Input.GetAxis("Camera Y Mouse") != 0)
                {
                    transform.Translate(Vector3.right * Time.deltaTime * CameraMoveMouse * Input.GetAxis("Camera Y Mouse"), Space.Self);
                }
            }
            else if (Input.GetAxis("Camera Rotation") != 0)
            {
                Screen.lockCursor = true;
                if (Input.GetAxis("Camera X Mouse") != 0)
                {
                    transform.Rotate(Vector3.up * Time.deltaTime * CameraRotateSpeed * Input.GetAxis("Camera Y Mouse"), Space.World);
                }
            } 

            transform.rotation = Quaternion.Euler(thiseulerX, transform.eulerAngles.y, transform.eulerAngles.z);

            if (Input.GetAxis("Move Camera Enabler") == 0)
            {
                if (Input.GetAxis("Camera Rotation") == 0 && Input.GetAxis("Camera Zoom") != 0)
                {
                    transform.Translate(Vector3.forward * Time.deltaTime * CameraZoomSpeed * Input.GetAxis("Camera Zoom"), Space.Self);
                    while (transform.position.y > CameraMax)
                    {
                        transform.Translate(Vector3.forward * Time.deltaTime / 100, Space.Self);
                    }
                    while (transform.position.y < CameraMin)
                    {
                        transform.Translate(Vector3.back * Time.deltaTime / 100, Space.Self);
                    }
                }
            }
        }
        else
        {
            Screen.lockCursor = false;
        }
    }

    bool hasInput()
    {
        if (
                Input.GetAxis("Camera X") != 0 ||
                Input.GetAxis("Camera Y") != 0 ||
                Input.GetAxis("Move Camera Enabler") != 0 ||
                Input.GetAxis("Camera Zoom") != 0 ||
                Input.GetAxis("Camera Rotation") != 0
           )
        {
            return true;
        }
        return false;
    }
}

Okay... here's all the relevant input settings from that project. Everything needs to match pretty much exactly for it to work (the names especially).

Edit: This is far from perfect... I have duplicate input types, and gravity doesn't need to be "9999"... but if you plug these values in it should work.

Input Settings

MCE Settings

Following this example word-for-word, I end up crashing Unity. Not cool.

Seems to be something specifically with the Camera Zoom. It would be nice if someone could update this with something less suboptimal.