Drag[en]gine Script Module DragonScript
1.21
|
Behavior element behavior adding collider support. More...
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... | |
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:
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.
Component is used for collision detection. If collider is dynamic component bones will be updated by the collider automatically.
Element class properties have the prefix "collider.".
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:
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:
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:
void Dragengine.Scenery.ECBehaviorCollider.addListenerFactory | ( | Block | blockFactory | ) |
void Dragengine.Scenery.ECBehaviorCollider.addListenerFactory | ( | ListenerFactory | factory | ) |
Add listener factory.
void Dragengine.Scenery.ECBehaviorCollider.createListeners | ( | Instance | instance | ) |
Create listeners from factories adding them to behavior instance.
void Dragengine.Scenery.ECBehaviorCollider.dispose | ( | ) |
Dispose of behavior.
Reimplemented from Dragengine.Scenery.DefaultECBehavior.
void Dragengine.Scenery.ECBehaviorCollider.forEachListenerFactory | ( | Block | ablock | ) |
Visit listener factories with block with argument ListenerFactory.
|
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.
ECComposeCollider Dragengine.Scenery.ECBehaviorCollider.getCollider | ( | ) |
Composeable collider for element class.
ECBehaviorComponent Dragengine.Scenery.ECBehaviorCollider.getComponent | ( | ) |
Component behavior.
ECBehaviorCollider Dragengine.Scenery.ECBehaviorCollider.new | ( | BehaviorElementClass | eclass, |
ECBehaviorComponent | component | ||
) |
Create behavior element class.
These values are optional and can be null: component.
ECBehaviorCollider Dragengine.Scenery.ECBehaviorCollider.new | ( | BehaviorElementClass | eclass, |
ECBehaviorComponent | component, | ||
String | prefix | ||
) |
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.