For all Unity developers and developers-to-be, both beginners and professionals!

Report article RSS Feed Isometric RTS camera in Unity

How to get an isometric RTS camera in Unity?

Posted by feillyne on Jul 21st, 2012
Basic Client Side Coding.

How to get an isometric RTS camera in Unity?

RTS camera

You just need to
1) create empty game object EyeSocket (Game Object -> Create Empty)

2) create EyeMovement Javascript script and attach it to EyeSocket

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

<- rotation coordinates should be exactly the same

javascript code:
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 &amp;&amp; Eye.camera.orthographicSize > 4)
    {
    Eye.camera.orthographicSize = Eye.camera.orthographicSize - 4;
    }
 
  //
  if (Input.GetAxis("Mouse ScrollWheel") < 0 &amp;&amp; Eye.camera.orthographicSize < 80)
    {
    Eye.camera.orthographicSize = Eye.camera.orthographicSize + 4;
    }

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

Important note: you must replace "& amp;& amp;" with two ampersands "&&" IndieDB/ModDB html editor converts them automatically to html code.

A clean version of this script is on Unity forums: Forum.unity3d.com

Post comment Comments
booman
booman Jul 24 2012, 7:27pm says:

cool, that seems pretty easy... should work for RPG camera view too

+2 votes     reply to comment
feillyne Author
feillyne Jul 25 2012, 5:44am replied:

Yep, totally. :-)

+1 vote   reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Established
Oct 31, 2010
Privacy
Public
Subscription
Open to all members
Homepage
Unity3d.com
Contact
Send Message
Email
Members Only
Membership
Join this group
Group Watch
Track this group
Tutorial
Browse
Tutorials
Report Abuse
Report article
Related Games
Tribal Lands
Tribal Lands Single Player Real Time Strategy
Related Engines
Unity
Unity Commercial Released May 30, 2005
Related Groups
Indie Devs
Indie Devs Hobbies & Interests group with 1,125 members
Unity devs
Unity devs Hobbies & Interests group with 1,224 members