A group dedicated to indie and standalone game development.

Post tutorial Report RSS Isometric RTS camera in Unity

How to get an isometric RTS camera in Unity?

Posted by on - 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

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

Comments
booman
booman

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

Reply Good karma Bad karma+2 votes
feillyne AuthorSubscriber
feillyne

Yep, totally. :-)

Reply Good karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Established
Privacy
Public
Subscription
Open to all members
Contact
Send Message
Membership
Join group
Group watch
Follow
Tutorial
Browse
Tutorials
Report
Report
Share
Related Games
Tribal Lands
Tribal Lands Real Time Strategy
Related Engines
Unity
Unity Commercial
Related Groups
Indie Devs
Indie Devs Hobbies & Interests with 1,438 members
Unity Devs
Unity Devs Hobbies & Interests with 1,617 members