User Tools

Site Tools


dragengine:modules:dragonscript:behavior_occupier

This is an old revision of the document!


ECBehaviorOccupier

Behavior in action (starting at timestamp 1:28)

Behavior element behavior adding support to uccipy an CBehaviorInteractionSpot.

CBehaviorInteractionSpot defines position and orientation actors or the player have to assume to interact properly with this element. The ECBehaviorOccupier behavior provides support to claim such interaction spots.

Instance Counts

Usually an element has one instance of ECBehaviorOccupier but it is possible to use multiple instance for example to track different interacions. Think of a chair the actor can sit down upon. The actor can use one occupier to track sitting on the chair while using another occupier to track interacting with something while being seated.

Element Class Properties

Element class properties have the prefix occupier. or occupier(id). if id is not empty.

Events

spotClaimed

Occupier claimed interaction spot.

===== spotReleased (Instance instance, ECBehaviorInteractionSpot.Instance interactionSpot)

Occupier released interaction spot.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace occupier with occupier(id).

occupier.release

Release interaction slot if one is occupied.

This is an example of using this action:

<action name='occupier.release'/>

occupier.check

Check one or more occupier parameters. Action succeeds if all parameter value matches their respective occupier parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a occupier parameter matches (or not).

ParameterValueDescription
occupyingtrue, falseOccupier is occupying an interaction spot

This is an example of using this action:

<sequence>
  <action name='occupier.check'>
    <parameter name='occupying'>true</parameter>
  </action>
  <!-- actions here run only if occupier is occupying an interaction spot -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace occupier with occupier(id).

occupier.check

Check one or more occupier parameters. Conditions returns true if all parameter value match their respective occupier parameter. This condition is typically used to run an action or sequence of actions as long as occupier conditions are true.

ParameterValueDescription
occupier.occupyingtrue, falseOccupier is occupying an interaction spot

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='occupier.occupying'>true</parameter>
  <condition>occupier.check</condition>
</action>

Required Behaviors

This behavior does not required other behaviors to be present.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorOccupier.

Since DragonScript Module Version 1.4

Use Cases

  • Ensure actor/player is at a specific position and orientation relative to an interactive element to ensure animation of actor/player and interactive element properly line up.
  • Ensure only one actor/player uses an interactive element at each time.

Element Class Example

class PlayerActor extends BaseActor
   public var ECBehaviorOccupier.Instance occupier
   
   public func new(PlayerActorClass eclass) super(eclass)
      // Store occupier instance. This way you can access it in player
      // actions without needing to look it up.
      occupier = eclass.occupier.instance(this)
   end
end

class PlayerActorClass extends BaseActorClass
   public var ECBehaviorOccupier occupier
   
   public func new() super("PlayerActor")
      // Create occupier. Game code can then use the occupier instance
      // to claim encountered ECBehaviorInteractionSpot instances
      occupier = ECBehaviorOccupier.new(this)
      
      // If you want to track more than one interaction spot you can
      // add multiple occupier instances each with an own ID.
      //occupierSeated = ECBehaviorOccupier.new(this, "seated")
   end
   
   public func Element createElement()
      // Create instance of player actor. If you do not want to store  the
      // occupier instance aside you can drop the createElement() function.
      // The base class then creates an instance of BaseActor
      return PlayerActor.new(this)
   end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorOccupier'>
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorOccupier' id='second'/>
</elementClass>

Live Examples

In the ExampleApp you can find a complete example of using this behavior:

  • InteractionSpotExampleClass.ds: Element class providing an interaction spot the player can use
  • BehaviorInteractToggle.ds: Interaction behavior allowing player to toggle the animated state of an element. This behavior stores the interaction spot the player has to claim.
  • PlayerActorClass.ds: Player actor class. Uses occupier behavior to safely do interactions.
  • PlayerActionInteractToggle.ds: Player action interacting with BehaviorInteractToggle. Tries to claim the assigned interaction spot and if successful moves to the spot and uses the element. Once finished releases the interaction spot.
You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_occupier.1746221962.txt.gz · Last modified: 2025/05/02 21:39 by dragonlord