{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorCollider** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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 [[behavior_component|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 [[behavior_component|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 [[behavior_component|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 [[#element_Class_example|Examples]] See also: * [[gamedev:colliders|Colliders]] ====== Instance Counts ====== This behavior can only be addec once on an element. ====== Element Class Properties ====== Element class properties have the prefix ''collider.''. ===== physicsType ===== Set physics type. * Full name: ''collider.physicsType'' * Type: enumeration * 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.| * Default Value: ''none'' * Example (*.deeclass) dynamic ===== localGravity ===== Set local gravity or ''null'' to use the world gravity. * Full name: ''collider.localGravity'' * Type: 3-component float vector * Default Value: ''null'' * Example (*.deeclass) ===== weight ===== Set weight in kg. * Full name: ''collider.weight'' * Type: float * Default Value: 1 * Restriction: At least 0 * Example (*.deeclass) 1.5 ===== enabled ===== Set enable collider. * Full name: ''collider.enabled'' * Type: boolean * Default Value: true * Example (*.deeclass) false ===== shape ===== Set shape if no component is used. * Full name: ''collider.shape'' * Type: string (shape format). See "Shape List Encoding" in CodecPropertyString. * Default Value: empty string * Example (*.deeclass) box:position,0,0.5,0:extends,2,1,0.5 ====== Events ====== This behavior has no events. ====== Required Behaviors ====== This behavior requires no other behaviors. ====== Optional Behaviors ====== * [[behavior_component|ECBehaviorComponent]]: If present ColliderComponent is created otherwise ColliderVolume. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). Saves these states: * Element position * Element orientation * Element scaling * Collider linear velocity * Collider angular velocity * If collider response type is ''dynamic'' and colider is ColliderRig or ColliderComponent writes these states of all dynamic bones: * Bone position * Bone orientation * Bone linear velocity * Bone angular velocity ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorCollider.html,ECBehaviorCollider~@#. Since DragonScript Module Version **1.0** ====== Use Cases ====== * Add physical presence to element in game world. ====== Element Class Example ====== 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 ====== Behavior Factory ====== Using element class supporting adding behaviors the behavior can be added like this: Use Case 1: Shape Collision dynamic Use Case 2: Component Collision. second dynamic ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]: