Drag[en]gine Script Module DragonScript  1.23
Dragengine.Scenery.ECBehaviorCollider Class Reference

Behavior element behavior adding collider support. More...

Inheritance diagram for Dragengine.Scenery.ECBehaviorCollider:
Dragengine.Scenery.DefaultECBehavior Dragengine.Scenery.ECBehavior Dragengine.Scenery.BehaviorCompatiblePersistency

Classes

class  BlockListenerFactory
 Factory creating listeners using block. More...
 
class  DefaultListener
 Default implementation of behavior instance listener. More...
 
class  Instance
 Behavior instance. More...
 
interface  Listener
 Listener for behavior instance events. More...
 
interface  ListenerFactory
 Factory creating listeners. More...
 

Public Member Functions

void addListenerFactory (Block blockFactory)
 Add listener factory using block. More...
 
void addListenerFactory (ListenerFactory factory)
 Add listener factory. More...
 
void createListeners (Instance instance)
 Create listeners from factories adding them to behavior instance. More...
 
void dispose ()
 Dispose of behavior. More...
 
void forEachListenerFactory (Block ablock)
 Visit listener factories with block with argument ListenerFactory. More...
 
ECComposeCollider getCollider ()
 Composeable collider for element class. More...
 
ECBehaviorComponent getComponent ()
 Component behavior. More...
 
ECBehaviorCollider new (BehaviorElementClass eclass, ECBehaviorComponent component)
 Create behavior element class. More...
 
ECBehaviorCollider new (BehaviorElementClass eclass, ECBehaviorComponent component, String prefix)
 
void setGhost ()
 Set up collider as ghost collider. More...
 
- Public Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
void assignInstanceIndex (int instanceIndex)
 Assign instance index. More...
 
String getBehaviorID ()
 Unique identifier of behavior. More...
 
String getID ()
 Identifier. More...
 
int getInstanceIndex ()
 Instance index. More...
 
void loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance)
 Load instance data of another behavior. More...
 
bool supportsBehaviorID (String identifier)
 Behavior supports loading instance data of another behavior. More...
 
- Public Member Functions inherited from Dragengine.Scenery.ECBehavior
ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance. More...
 

Static Public Member Functions

static ECBehaviorCollider getBehaviorIn (BehaviorElementClass eclass)
 Get behavior in element class or null if absent. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
DefaultECBehavior new (BehaviorElementClass eclass)
 Create default composeable behavior with empty identifier. More...
 
DefaultECBehavior new (BehaviorElementClass eclass, String id)
 Create default composeable behavior. More...
 
void setBehaviorID (String identifier)
 Set behavior identifier. More...
 
void useClassNameAsBehaviorID ()
 Set behavior identifier to "<class-name>:<identifier>". More...
 
void useFullyQualifiedClassNameAsBehaviorID ()
 Set behavior identifier to "<fully-qualified-class-name>:<identifier>". More...
 

Detailed Description

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:

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 func new()
var ECBehaviorCollider collider = ECBehaviorCollider.new(this, null)
// assign collision shape or collision rig to the collider
ECBehaviorComponent.new(this, collider)
end
end
ECBehaviorCollider new(BehaviorElementClass eclass, ECBehaviorComponent component)
Create behavior element class.
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 func new()
var ECBehaviorComponent component = ECBehaviorComponent.new(this, null)
ECBehaviorCollider.new(this, component)
end
end

Element class properties have the prefix "collider.".

Collision listening

The default collision behavior clears the linear and angular velocities. To add meaningful collision behavior add listeners. If one or more listener are present the default collision behavior is disabled and the listeners are responsible. At least one listener has to do collision handling in a way that the current collision is not happening again. This can be done by modifying the velocities of the affected colliders, changing collision filters or removing elements from the game world altogether. The ECBehaviorCollider assigns the owner BehaviorElement as owner of the collider. Hence you can retrieve the BehaviorElement represented by a collider like this:

// check if a collider has been hit (other possibilities exist like height-terrain)
if info.getCollider() != null
// check if the owner of the collider is of type BehaviorElement
if info.getOwner() castable BehaviorElement
var BehaviorElement element = info.getOwner() cast BehaviorElement
// work with the element, for example check what behaviors it has attached
end
end

Another way is to subclass ElementVisitor. This is a more object-oriented approach and keeps the code cleaner especially if the behavior is able to work with different types of elements. This way would look roughly like this:

// check if a collider has been hit (other possibilities exist like height-terrain)
if info.getCollider() != null
// check if the owner of the collider is of type Element
if info.getOwner() castable Element
// visit the element to apply the desired actions
(info.getOwner() cast Element).visit(MyElementCollisionVisitor.new())
end
end

This behavior does require the element class to be persistable (setPersistable) only if the physics type is set to anything else but CollisionResponse.none .

TODO: possible behaviors using this system:

  • sliding collision response: slides kinematic colliders along walls like actors do
  • power ups: typical example of a an element touched by the actor that vanishes when touched adding all kinds of abilities. this would be an example of behaviors on different elements interacting. requires two behaviors. one behavior is the power up itself which identifies the element as a power up that can be consumed. the second is the touch power up behavior placed on the interacting element. it uses getInstanceIn() to check if the hit element has the power up behvaior and if so removes it from the game world and applies the effects.

Member Function Documentation

◆ addListenerFactory() [1/2]

void Dragengine.Scenery.ECBehaviorCollider.addListenerFactory ( Block  blockFactory)

Add listener factory using block.

Block receives as parameter Instance and returns Listener.

◆ addListenerFactory() [2/2]

void Dragengine.Scenery.ECBehaviorCollider.addListenerFactory ( ListenerFactory  factory)

Add listener factory.

◆ createListeners()

void Dragengine.Scenery.ECBehaviorCollider.createListeners ( Instance  instance)

Create listeners from factories adding them to behavior instance.

◆ dispose()

void Dragengine.Scenery.ECBehaviorCollider.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

◆ forEachListenerFactory()

void Dragengine.Scenery.ECBehaviorCollider.forEachListenerFactory ( Block  ablock)

Visit listener factories with block with argument ListenerFactory.

◆ getBehaviorIn()

static ECBehaviorCollider Dragengine.Scenery.ECBehaviorCollider.getBehaviorIn ( BehaviorElementClass  eclass)
static

Get behavior in element class or null if absent.

Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorCollider.

◆ getCollider()

ECComposeCollider Dragengine.Scenery.ECBehaviorCollider.getCollider ( )

Composeable collider for element class.

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorCollider.getComponent ( )

Component behavior.

◆ new() [1/2]

ECBehaviorCollider Dragengine.Scenery.ECBehaviorCollider.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component 
)

Create behavior element class.

These values are optional and can be null: component.

◆ new() [2/2]

ECBehaviorCollider Dragengine.Scenery.ECBehaviorCollider.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
String  prefix 
)

◆ setGhost()

void Dragengine.Scenery.ECBehaviorCollider.setGhost ( )

Set up collider as ghost collider.

Ghost colliders have empty collision filter and a small sphere shape. They collide with nothing and are useful to attach elements composing only of resources like ECBehaviorLight.


The documentation for this class was generated from the following file: