Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorCollider
Behavior element behavior adding collider support.
Colliders provide physical presence to elements allowing them to collide with other colliders, attaching them to other colliders and moving the element through the game world.
This element behavior is often required by other element behaviors to be present to function correctly.
Since this collider repositions the element upon changing position and orientation this element behavior can be present only once in a BehaviorElement. Trying to add more than one instance results in an exception thrown.
If you need additional colliders for example to sense objects using collision detection then you need to use other ECBehavior providing the desired behavior. These allow to be added multiple times.
If the ECBehaviorComponent behavior is present in the behavior element before this behavior is added a ColliderComponent is created. The component is used for collision detection and updated automatically by the collider. This is required if you intend to use per-bone collisions matching animation state or physical simulations like rag-dolls.
If the ECBehaviorComponent behavior is added after this behavior then a ColliderVolume is created. The rig assigned to the component is only used for animation purpose. The ECBehaviorComponent will then statically attach to the collider.
Hence these two use cases are possible depending on the order the behaviors are added: Shape Collision, Component Collision. See Examples
See also:
This behavior can only be addec once on an element.
Element class properties have the prefix collider.
.
Set physics type.
collider.physicsType
Allowed Values:
Value | Description |
---|---|
none | No response. Collider is not moving and will not move by collisions. |
dynamic | Dynamic collision response. Collider reacts to impacts using physical simulation. |
kinematic | Kinematic collision response. Game scripts define the collision response. |
none
<string name='collider.physicsType'>dynamic</string>
Set local gravity or null
to use the world gravity.
collider.localGravity
null
<vector name='collider.localGravity' x='0' y='-0.5' z='0'/>
Set weight in kg.
collider.weight
<float name='collider.weight'>1.5</float>
Set enable collider.
collider.enabled
<boolean name='collider.enabled'>false</boolean>
Set shape if no component is used.
collider.shape
<string name='collider.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>
This behavior has no events.
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable). Saves these states:
dynamic
and colider is ColliderRig or ColliderComponent writes these states of all dynamic bones:Since DragonScript Module Version 1.0
Use Case 1: Shape Collision. Component is only visual. For collision only static collision shape is used. The component is attached statically to the collider and does not collide. If collider is dynamic physics simulation will be done using collision shape only.
class MyElementClass extends BehaviorElementClass public var ECBehaviorCollider collider public var ECBehaviorComponent component func new() collider = ECBehaviorCollider.new(this, null) // assign collision shape or collision rig to the collider component = ECBehaviorComponent.new(this, collider) end end
Use Case 2: Component Collision. Component is used for collision detection. If collider is dynamic component bones will be updated by the collider automatically.
class MyElementClass extends BehaviorElementClass public var ECBehaviorCollider collider public var ECBehaviorComponent component func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) end end
Using element class supporting adding behaviors the behavior can be added like this:
Use Case 1: Shape Collision
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorCollider'> <!-- no behavior has been added before so no component behavior will be used --> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.physicsType'>dynamic</string> </behavior> <!-- adding the component will detect the previously added collider and use it --> <behavior type='ECBehaviorComponent'/> </elementClass>
Use Case 2: Component Collision.
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <!-- no collider is present yet so component will not use any collider --> <behavior type='ECBehaviorComponent'/> <behavior type='ECBehaviorCollider'> <!-- optional: by default the previously added component is detected and used. to use a different component add one with a different id and use the id here --> <string name='component'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.physicsType'>dynamic</string> </behavior> </elementClass>