Friday, October 17, 2014

Isometric Fun?

Working with Isometric views...
I have created a test environment to work on functionality and scripts. So in working with 2D isometric views the biggest issue is the depth/draw call order of the environment and how the character interacted with objects.


Pic 0
When objects are placed in the scene, depending on the layer they are on determines the draw order. So by default, the player can run over objects that they should not be able to.

Pic 1
To assist with the issue, collider is placed on an 2D object. Now, when the player collides with the object they cannot run through it.

Pic 2
So the next issue is to determine when the player is in front or behind an object with a collider in place. Currently the player is in front and collides correctly.

In researching, there are a few methods to create the illusion of depth for the player.
- Slice the sprites based on the characters
- Get the Y position of the player and objects and change the sorting order
- Use multiple layers to move objects based on the players in front or behind position

The method I decided to try was getting the Y position based on the camera and update the sorting order on the layer. I found a useful script (below) on the Unity forum that would be helpful to achieve this function. This is placed on the player and all the objects in the scene.

Pic 3
Now the player can run in front and behind objects based on the Y position of the camera. So the draw order functions normally.

Script (in Javascript):
var sprite : SpriteRenderer;
function LateUpdate () 
{
sprite = GetComponent(SpriteRenderer);
sprite.sortingOrder = Camera.main.WorldToScreenPoint(sprite.bounds.min).y * -1;
}


Isometric character and house by Reiner Prokein  (http://www.reinerstilesets.de)

No comments:

Post a Comment