IsoRigidbody#

class in UltimateIsometricToolkit.Scripts.Physics / Inherits from MonoBehaviour

Description#

Rigidbody component for isometric objects

Allows to add forces

Variables#

Type Name Description
bool ShowBounds Flag to draw gizmo bounds of the IsoTransfrom in scene view
float Mass Rigidbody mass (default 1)
float Drag Velocity damping factor
bool UseGravity Controls whether gravity affects this rigidbody.
bool IsKinematic Controls whether physics affects the rigidbody.
RigidbodyInterpolation Interpolate Interpolation allows you to smooth out the effect of running physics at a fixed frame rate.
CollisionDetectionMode CollisionDetectionMode The Rigidbody's collision detection mode.
Vector3 CenterOfMass CenterOfMass for this Rigidbody
Vector3 Velocity Current velocity
float MaxDepenetrationVelocity Maximum velocity of a rigidbody when moving out of penetrating state.
float SleepThreshold The mass-normalized energy threshold, below which objects start going to sleep.
bool isSleeping Is this object in sleeping mode (readonly)

Note

Angular velocity is ignored and set to 0 at all times

Public functions#

Important

Forces can be applied only to an active rigidbody.

void AddExplosionForce(float explosionForce, Vector3 explosionPosition, float explosionRadius, float upwardsModifier = 0.0F, ForceMode mode = ForceMode.Force)#

Adds an explosion force to the IsoRigidbody and objects in the explosion radius

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public void foo() {
  // add force and delete this object after 1 second
  isoRigidbody.AddExplosionForce(10,Vector.up * 10, 10);                                                      
  StartCoroutine(DeleteAfterTimePassed(1));
}

public IEnumerator DeletaAfterTimePassed(float duration) {
  var start = Time.time;
  while(Time.time < start + duration)
    yield return null;
  Destroy(this.gameObejct);
}

void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)#

Adds a force to this Rigidbody

1
2
3
4
5
public void Update() {
  // add up force on W pressed
  if(Input.GetKeyDown(KeyCode.W))
    isoRigidbody.AddForce(Vector.up * 10);                                                      
}

void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode = ForceMode.Force)#

Applies force at position. Torque will be ignored. In order to make sense of this function position should be close to the IsoTransform.Position

1
2
3
4
public void ApplyForce(IsoRigidbody body) {
        Vector3 direction = body.GetComponent<IsoTransform>.Position - GetComponent<IsoTransform>().Position;
        body.AddForceAtPosition(direction.normalized, GetComponent<IsoTransform>.Position);
    }

void AddRelativeForce(Vector3 force, ForceMode mode = ForceMode.Force)#

Applies a force to the rigidbody relative to its coordinate system.

1
2
3
4
float thrust = 1f;
void FixedUpdate() {
        gameObject.GetCompoent<IsoRigidbody>().AddRelativeForce(Vector3.forward * thrust);
    }

SweepTest(Vector3 direction, out IsoRaycastHit hitInfo, float maxDistance = Mathf.Infinity, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)#

1
Tests if a rigidbody would collide with anything, if it was moved through the scene.
1
2
3
4
5
IsoRaycastHit hit;
       if (rb.SweepTest (transform.forward, out hit, collisionCheckDistance)) {
           aboutToCollide = true;
           distanceToCollision = hit.distance;
       }

IsoRaycastHit[] SweepTestAll(Vector3 direction, float maxDistance = Mathf.Infinity, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)#

Like IsoRigidbody.SweepTest, but returns all hits. The sweep may return multiple hits against the same collider if more then one of the rigidbody's attached colliders would hit it.

Note that this function only works when a primitive collider type (sphere, cube or capsule) or a convex mesh is attached to the rigidbody object - concave mesh colliders will not work, although they can be detected in the scene by the sweep.

This function can only return up to 128 hits.