Drag[en]gine Script Module DragonScript  1.21
Dragengine.Scenery.ECBehaviorHitScan Class Reference

Behavior adding hit-scan support to elements. More...

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

Classes

class  Instance
 Behavior instance. More...
 

Public Member Functions

ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance. More...
 
void dispose ()
 Dispose of behavior. More...
 
ECPString getBone ()
 Test bone. More...
 
ECBehaviorCollider getCollider ()
 Collider behavior or null. More...
 
ECComposeCollisionFilter getCollisionFilter ()
 Collision filter for AI collider. More...
 
ECBehaviorComponent getComponent ()
 Component behavior or null. More...
 
ECPVector getDirection ()
 Normalized test direction. More...
 
ECPVector getOrientation ()
 Test orientation. More...
 
ECPVector getOrigin ()
 Test origin. More...
 
ECPFloat getRange ()
 Test range. More...
 
Instance instance (BehaviorElement element)
 Get instance in element from owner element class. More...
 
ECBehaviorHitScan new (BehaviorElementClass eclass, ECBehaviorCollider collider, ECBehaviorComponent component)
 Create behavior element class. More...
 
ECBehaviorHitScan new (BehaviorElementClass eclass, ECBehaviorCollider collider, ECBehaviorComponent component, String id)
 
ECBehaviorHitScan new (BehaviorElementClass eclass, ECBehaviorCollider collider, ECBehaviorComponent component, String id, String prefix)
 
- 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...
 

Static Public Member Functions

static Array getAllBehaviorsIn (BehaviorElementClass eclass)
 Get list of all behaviors in element. More...
 
static Array getAllInstancesIn (BehaviorElement element)
 Get list of all instances in element. More...
 
static ECBehaviorHitScan getBehaviorIn (BehaviorElementClass eclass)
 Get behavior in element class or null if absent. More...
 
static ECBehaviorHitScan getBehaviorIn (BehaviorElementClass eclass, String id)
 Get behavior with id in element class or null if absent. More...
 
static Instance getInstanceIn (BehaviorElement element)
 Get instance in element or null if absent. More...
 
static Instance getInstanceIn (BehaviorElement element, String id)
 Get instance with id in element 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 adding hit-scan support to elements.

Behavior supports using one or more collider collision tests to do one or more hit scans for example to check for weapon projectile impacts. Hit scans are done once then the result can be examine. To use this behavior add ECBehaviorCollider then this behavior. The collider is used to carry the collision tests.

To start a series of hit-scans call one of the start() methods to set up the hit-scans. You can set up the hit-scans manually or use the convenience methods to set up hit-scans matching typical use cases. Starting hit scans has to be done during think() time.

After setting up hit scans during think() the physics module carries out the desired collision tests. The result can be evaluated during the following postThink() or the the next think() call.

A typical scenario is a projectile weapon triggered by the actor. The weapon element has the ECBehaviorHitScan. When the player triggers the weapon the hit-scan is started() in the think() phase and the hits evaluated in the postThink() phase.

// Weapon element befitted with hit-scan support
class MyWeaponClass extends BehaviorElementClass
public var ECBehaviorCollider collider
public var ECBehaviorHitScan hitScan
public func new()
collider = ECBehaviorCollider.new(this, null)
hitScan = ECBehaviorHitScan.new(this, collider)
hitScan.getCollisionFilter().setCollisionFilter(...)
end
end
// Player actor action triggering the weapon
class MyPlayerAction extends BAAFirstPerson
public func new()
end
public var bool doesFireWeapon
public func void think(float elapsed)
super.think(elapsed)
if doesPlayerFireWeapon()
var BehaviorElement weapon = getPlayerWeapon()
ECBehaviorHitScan.getInstanceIn(weapon).start( ... )
doesFireWeapon = true
end
end
public func void postThink(float elapsed)
super.postThink(elapsed)
if doesFireWeapon
doesFireWeapon = false
var BehaviorElement weapon = getPlayerWeapon()
ECBehaviorHitScan.getInstanceIn(weapon).forEachHit(block ColliderCollisionTest test
// evaluate hits for example damaging first hit for each hit-scan if present
if test.hitCollider(0) != null
var BehaviorElement target = test.hitCollider(0).getOwner() cast BehaviorElement
// damage target
end
end)
end
end
end
ECBehaviorHitScan new(BehaviorElementClass eclass, ECBehaviorCollider collider, ECBehaviorComponent component)
Create behavior element class.
static Instance getInstanceIn(BehaviorElement element)
Get instance in element or null if absent.
ECComposeCollisionFilter getCollisionFilter()
Collision filter for AI collider.

Another possibility is to create a behavior attached to the weapon element doing the same. This moves the weapon hit and damage logic to a behavior with the actor only triggering the behavior and having nothing to do with it.

Member Function Documentation

◆ createInstance()

ECBehaviorInstance Dragengine.Scenery.ECBehaviorHitScan.createInstance ( BehaviorElement  element)

Create Behavior instance.

Implements Dragengine.Scenery.ECBehavior.

◆ dispose()

void Dragengine.Scenery.ECBehaviorHitScan.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

◆ getAllBehaviorsIn()

static Array Dragengine.Scenery.ECBehaviorHitScan.getAllBehaviorsIn ( BehaviorElementClass  eclass)
static

Get list of all behaviors in element.

Returns list contains ECBehaviorHitScan behaviors in the order they have been created in the element.

◆ getAllInstancesIn()

static Array Dragengine.Scenery.ECBehaviorHitScan.getAllInstancesIn ( BehaviorElement  element)
static

Get list of all instances in element.

Returns list contains ECBehaviorHitScan.Instance instances in the order they have been created in the element.

◆ getBehaviorIn() [1/2]

static ECBehaviorHitScan Dragengine.Scenery.ECBehaviorHitScan.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.

◆ getBehaviorIn() [2/2]

static ECBehaviorHitScan Dragengine.Scenery.ECBehaviorHitScan.getBehaviorIn ( BehaviorElementClass  eclass,
String  id 
)
static

Get behavior with id in element class or null if absent.

Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorHitScan with specific identifier.

◆ getBone()

ECPString Dragengine.Scenery.ECBehaviorHitScan.getBone ( )

Test bone.

◆ getCollider()

ECBehaviorCollider Dragengine.Scenery.ECBehaviorHitScan.getCollider ( )

Collider behavior or null.

◆ getCollisionFilter()

ECComposeCollisionFilter Dragengine.Scenery.ECBehaviorHitScan.getCollisionFilter ( )

Collision filter for AI collider.

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorHitScan.getComponent ( )

Component behavior or null.

◆ getDirection()

ECPVector Dragengine.Scenery.ECBehaviorHitScan.getDirection ( )

Normalized test direction.

◆ getInstanceIn() [1/2]

static Instance Dragengine.Scenery.ECBehaviorHitScan.getInstanceIn ( BehaviorElement  element)
static

Get instance in element or null if absent.

Use this method to check if a particular BehaviorElement contains a behavior instance of type ECBehaviorHitScan.Instance . If more than one instance is present returns the first instance.

◆ getInstanceIn() [2/2]

static Instance Dragengine.Scenery.ECBehaviorHitScan.getInstanceIn ( BehaviorElement  element,
String  id 
)
static

Get instance with id in element or null if absent.

Use this method to check if a particular BehaviorElement contains a behavior instance of type ECBehaviorHitScan.Instance with specific identifier.

◆ getOrientation()

ECPVector Dragengine.Scenery.ECBehaviorHitScan.getOrientation ( )

Test orientation.

◆ getOrigin()

ECPVector Dragengine.Scenery.ECBehaviorHitScan.getOrigin ( )

Test origin.

◆ getRange()

ECPFloat Dragengine.Scenery.ECBehaviorHitScan.getRange ( )

Test range.

◆ instance()

Instance Dragengine.Scenery.ECBehaviorHitScan.instance ( BehaviorElement  element)

Get instance in element from owner element class.

◆ new() [1/3]

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

Create behavior element class.

These values are optional and can be null: component.

◆ new() [2/3]

ECBehaviorHitScan Dragengine.Scenery.ECBehaviorHitScan.new ( BehaviorElementClass  eclass,
ECBehaviorCollider  collider,
ECBehaviorComponent  component,
String  id 
)

◆ new() [3/3]

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

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