Isometric RTS camera

How to make a simple isometric RTS camera?

You just need to

1) create an empty game object EyeSocket (Game Object → Create Empty)

  • set its position to (X, Y, Z) 0, 130, 0

2) create EyeMovement Javascript script and attach it to EyeSocket

3) add camera object called Eye (Create Other → Camera) and attach it to EyeSocket

  • set its Rotation to (X, Y, Z) 30, 45, 0
  • set its Projection to Orthographic
  • set its Size to 50

    ← rotation coordinates should be exactly the same

EyeMovement.js

function Update () {
           
    /////////////////////
    //keyboard scrolling
   
    var translationX : float = Input.GetAxis("Horizontal");
    var translationY : float = Input.GetAxis("Vertical");
    var fastTranslationX : float = 2 * Input.GetAxis("Horizontal");
    var fastTranslationY : float = 2 * Input.GetAxis("Vertical");
   
    if (Input.GetKey(KeyCode.LeftShift))
        {
        transform.Translate(fastTranslationX + fastTranslationY, 0, fastTranslationY - fastTranslationX);
        }
    else
        {
        transform.Translate(translationX + translationY, 0, translationY - translationX);
        }

    ////////////////////
    //mouse scrolling
   
    var mousePosX = Input.mousePosition.x;
    var mousePosY = Input.mousePosition.y;
    var scrollDistance : int = 5;
    var scrollSpeed : float = 70;

    //Horizontal camera movement
    if (mousePosX < scrollDistance)
        //horizontal, left
        {
        transform.Translate(-1, 0, 1);
        }
    if (mousePosX >= Screen.width - scrollDistance)
        //horizontal, right
        {
        transform.Translate(1, 0, -1);
        }

    //Vertical camera movement
    if (mousePosY < scrollDistance)
        //scrolling down
        {
        transform.Translate(-1, 0, -1);
        }
    if (mousePosY >= Screen.height - scrollDistance)
        //scrolling up
        {
        transform.Translate(1, 0, 1);
        }
   
    ////////////////////
    //zooming
    var Eye : GameObject = GameObject.Find("Eye");
   
    //
    if (Input.GetAxis("Mouse ScrollWheel") > 0  Eye.camera.orthographicSize > 4)
        {
        Eye.camera.orthographicSize = Eye.camera.orthographicSize - 4;
        }
   
    //
    if (Input.GetAxis("Mouse ScrollWheel") < 0  Eye.camera.orthographicSize < 80)
        {
        Eye.camera.orthographicSize = Eye.camera.orthographicSize + 4;
        }

    //default zoom
    if (Input.GetKeyDown(KeyCode.Mouse2))
        {
        Eye.camera.orthographicSize = 50;
        }
       
}

EyeSocket + Eye as a prefab, and EyeMovement.js attached. Please note that you need to set EyeSocket position to (X, Y, Z) 0, 130, 0 to get it to move properly.

990565–36658–$isometric_rts_camera.unitypackage (3.19 KB)

nice work. thanks :slight_smile:

How to I limit the mouse movements? On the keyboard I was able to set horizontal and vertical limits so that you couldn’t scroll too far off my scene, but I can’t seem to figure out how to do this with the mouse. Here is my code:

	private float leftSide = -100f;
	private float rightSide = -80f;
	private float topSide = -80f;
	private float bottomSide = -100f;
	
	// Update is called once per frame
	void Update () 
	{
	
 		/////////////////////
		//keyboard scrolling		
		float translationX = Input.GetAxis("Horizontal");
		float translationZ = Input.GetAxis("Vertical");
			
		float toX = translationX + translationZ;			
		if (transform.position.x + toX < leftSide)
		{
			toX = 0;
		}
		if (transform.position.x + toX > rightSide)
		{
			toX = 0;
		}
		float toZ = translationZ - translationX;			
		if (transform.position.z + toZ > topSide)
		{
			toZ = 0;
		}
		if (transform.position.z + toZ < bottomSide)
		{
			toZ = 0;
		}
		transform.Translate(toX, 0, toZ); 
		
		
		////////////////////
		//mouse scrolling	
		float mousePosX = Input.mousePosition.x;
		float mousePosY = Input.mousePosition.y;
		int scrollDistance = 1;
		float scrollSpeed = 70;
		
		//Horizontal camera movement
		//horizontal, left
		if (mousePosX < scrollDistance)
		{ 
			transform.Translate(-1, 0, 1);
		} 
		//horizontal, right
		if (mousePosX >= Screen.width - scrollDistance)
		{ 
			transform.Translate(1, 0, -1);
		} 
		
		//Vertical camera movement
		//scrolling down
		if (mousePosY < scrollDistance)
		{
			transform.Translate(-1, 0, -1);
		} 
		//scrolling up
		if (mousePosY >= Screen.height - scrollDistance)
		{
			transform.Translate(1, 0, 1);
		}
}

Hi,
How I rotate the camera, please?
Thanks

//rotate
if (Input.GetMouseButton(2))
{
translationX = Input.GetAxis (“Mouse X”);
transform.RotateAround(Vector3.up, translationX * cameraSpeed * Time.deltaTime);

}

this only works in c#. You will have to define camera speed to determine how quickly it will rotate.

I have a question though. I converted your code into c# and it works great but I do not know how to change the camera speed on the zoom or x/y translations.

This is a RTS camera I’have created some time ago. Maybe it can help someone.
[Post]
[Github link]

Looks like a solid camera. Thanks for the script :slight_smile: I haven’t quite mastered rotation yet so this should help a lot.