Chain Collider2D Component

The ChainCollider2D class is a component in Tsar engine used to define a chain of lines to add outline to a 2D rigidbody.
There are two types of colliders: solid and sensor.

  • Solid -> default collider which provides collision and other bodies with solid colliders cannot pass through it. IsSensor should be false.
  • Sensor -> collider which doesn't provide collision and other colliders pass through (overlap) it. IsSensor should be true.

Below is an image showing ChainCollider2D using current Debug rendering inside Tsar. You can change collider color in Editor from Settings->Physics2D->Gizmo.
Currently all lines share the same Physics Material.


Class Declaration

class ChainCollider2D : public Component

This class inherits from the Component class and adds functionality related to defining shape outline of a Rigidbody for simulating 2D physics.


Properties

The ChainCollider2D class exposes properties (that can also be accessed via getter and setter functions). These properties allow users to manipulate the shape properties of the object in a more intuitive manner:


float Restitution From Physics Material. Energy conservation coefficient. 1 means perfect bounce with no energy loss, 0 means perfect absorbtion with no bounce.

  • Get: GetRestitution()
  • Set: SetRestitution(float restitution)
    • restitution - should be value between [0; 1].

float Friction From Physics Material. Friction coefficient, 0 means no friction(slippery, like ice), 1 means high friction(grippy, like rubber), values >1 are allowed.

  • Get: GetFriction()
  • Set: SetFriction(float friction)
    • friction - should be non-negative value.

bool IsSensor Is the shape sensor or not(solid)? true means no collision, false means solid collider providing collision.
Default is false.

  • Get: GetIsSensor()
  • Set: SetIsSensor(bool isTrigger)
    • isTrigger - true makes shape like ghost/hollow detector, false makes shape solid.

bool EnableCollisionEvents Should collision events be registered from this shape and trigger Enter/Exit events in scripting.
Requires IsSensor=false. This itself doesn't affect collisions.

  • Get: GetEnableCollisionEvents()
  • Set: SetEnableCollisionEvents(bool enableCollisionEvents)
    • enableCollisionEvents - true enables event registration, false disables event registration.

bool EnableHitEvents Should hit events be registered from this shape and trigger Enter/Exit events in scripting.
Requires IsSensor=false and EnableCollisionEvents=true to work. This itself doesn't affect collisions.

  • Get: GetEnableHitEvents()
  • Set: SetEnableHitEvents(bool enableHitEvents)
    • enableHitEvents - true enables event registration, false disables event registration.

bool EnableSensorEvents Should sensor events be registered from this shape and trigger Enter/Exit events in scripting.
Requires IsSensor=true. This itself doesn't affect collisions.

  • Get: GetEnableSensorEvents()
  • Set: SetEnableSensorEvents(bool enableSensorEvents)
    • enableSensorEvents - true enables event registration, false disables event registration.