IsoPhysics#

class in UltimateIsometricToolkit.Scripts.Physics

Description#

Physics helper class for Raycasting

Public static Functions#


static bool Raycast(Vector3 origin, Vector3 direction,out IsoRaycastHit isoRaycastHit, float maxDistance = Mathf.Infinity, int layermask = Physics.DefaultRaycastLayers)#

Raycasts from origin to direction against any other IsoCollider. Both origin and direction are in isometric space

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void Update() {
  if (Input.GetKeyDown("space")) {
                //check vertical distance
                IsoRaycastHit hit;
                var maxDistanceToGround = 1f;
                if (IsoPhysics.Raycast(_isoTransform.Position, Vector3.down, out hit, maxDistanceToGround)) {
                    //add jump force
                    _isoRigidbody.AddForce(Vector3.up*JumpForce);
                }
            }
}

Note

IsoColliders are instantiated on Start(), so Raycasting in a Start() function of another script may result in a false negative due to a non-deterministic execution order of scripts in unity.


static bool Raycast(Ray ray, out IsoRaycastHit isoRaycastHit, float maxDistance = Mathf.Infinity, int layermask = Physics.DefaultRaycastLayers)#

Raycast along a ray.

Note

Ray origin and direction are in isometric space.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
void Update() {
  //creates a ray from mouse position on near plane and direction (0,0,1) in isometric space
  var isoRay = Isometric.MouseToIsoRay();

  //do an isometric raycast on left mouse click
  if (Input.GetMouseButtonDown(0)) {
    IsoRaycastHit isoRaycastHit;
    //raycast through image plane
    if (IsoPhysics.Raycast(isoRay, out isoRaycastHit)) {
        Debug.Log("we clicked on " + isoRaycastHit.Collider.name + " at " + isoRaycastHit.Point);
    }
  }
}

static IsoRaycastHit[] RaycastAll(Ray ray, float maxDistance = Mathf.Infinity, int layerMask = Physics.DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)#

Like IsoPhysics.Raycast but returns all hits


static bool BoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction,out IsoRaycastHit isoRaycastHit, Quaternion orientation, float maxDistance = Mathf.Infinity, int layerMask = Physics.DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)#

Like IsoPhysics.BoxCast but a box instead of a ray