Isometric#

class in UltimateIsometricToolkit.Scripts.Utils

Description#

Isometric helper class with utility functions

Variables#

Type Name Description
<static> Matrix4x4 IsoMatrix Current IsoMatix that projects from isometric to unity space (matrix inverse projects from unity to isometric space)

Public Functions#


static Vector3 IsoToUnitySpace(Vector3 isoVector)#

Converts a Vector from isometric to unity space

1
2
3
4
5
void foo() {
  var positionInIsoSpace = new Vector3(10,0,0);
  var samePositionInUnitySpace = Isometric.IsoToUnitySpace(positionInIsoSpace);
  Assert.NotEqual(positionInIsoSpace,samePositionInUnitySpace);
}

static Vector3 UnityToIsoSpace(Vector3 vector)#

Converts a Vector from unity to isometric space

1
2
3
void foo() {
  var positionInUnitySpace = Isometric.UnityToIsoSpace(new Vector3(10,0,0))
}

static Matrix4x4 GetProjectionMatrix(Projection projection, float xRot,float yRot)#

Returns to correct projection matrix for a given projection and optional global xRot,yRot

Hint

Depending on the projection the xRot,yRot may be fixed and have no impact on the output matrix


static Quaternion GetProjecitonQuaternion(Projection projection, float xRot, float yRot)#

Equivalent to GetProjectionMatrix but returns a quaternion rather than a matrix

1
2
3
4
"""Rotates a 3d object to fit the sprites pre-rendered rotation"""
void foo() {
  this.transform.rotation *= Isometric.GetProjectionMatrix(Projection.Dimetric1To2,0,0);
}

static Vector3 UnityToIsoSpace(Vector2 xyPos, Vector3 planeNormalVector, float offset)#

Returns the isometric position to a xy position in unity space. Works by raycasting from (x,y) in direction z-forward through an isometric plane defined by plane's normal vector and offset.

Hint

This allows to find an isometric position when we only have a 2d position in unity space like mouse/touch positions, ui positions, etc.


Vector3 ScreenToIsoPoint(Vector2 screenSpacePoint, float zOffset = 0f, Camera cam = null)#

Returns the isometric postion relative to a screen space position in pixels Raycasts from screenSpacePoint through the isometric plane with elevation z.

Note

  • Output vector will always have z=zOffset
  • Will choose the main camera by default

static Ray ScreenSpaceToIsoRay(Vector2 screenSpacePoint, Camera camera = null)#

Returns a Ray that casts into the sceen from a given screen space point in pixels

Note

  • Will choose the main camera by default

static Ray MouseToIsoRay()#

Returns the ScreenSpaceToIsoRay for the current mouse postion

1
2
3
public static Ray MouseToIsoRay() {
    return ScreenSpaceToIsoRay(Input.mousePosition);
}