{{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]] >> **ECBehaviorOccupier**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorOccupier ======
{{youtube>BbP-lMrr0tQ?medium}}
Behavior in action (starting at timestamp 1:28)
Behavior element behavior adding support to uccipy an [[behavior_interactionspot|CBehaviorInteractionSpot]].
[[behavior_interactionspot|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 =====
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.update =====
Set one or more occupier parameters.
^Parameter^Value^Description^
|release| |Release interaction slot if one is occupied.|
|interactElement.assign|string|Assign interaction slot element to [[behavior_interactionelement|ECBehaviorInteractionElement]] with identifier matching value string. Action fails if no interaction spot is occupied or interact element behavior is absent|
|claim|string|Claim interaction zone present in the [[behavior_interactionelement|ECBehaviorInteractionElement]] with identifier matching value string|
|claim.id|string|Identifier of interaction spot to claim|
|move| |Move to occupied interaction spot. Uses [[behavior_actormover|ECBehaviorActorMover]] to move to world position defined by interaction spot|
|move.distance|float|Distance in meters to approach interaction spot world position before finish moving|
|align| |Align with occupied interaction spot. Uses [[behavior_alignactor|ECBehaviorAlignActor]] to align actor with world position and orientation defined by interaction spot. If interaction spot defines a look-at position the [[behavior_conversationactor|ECBehaviorConversationActor]] is used to make the actor look at this position while aligning. After aligning the [[behavior_conversationactor|ECBehaviorConversationActor]] keeps the look-at. You have to clear it using action ''conversationActor.update'' and parameter ''headLookAt.clear''. Doing this while no look-at is in place is fine and thus should be always done|
|interact|string|Interact with grab spot. If element is absent action fails. Runs interaction with name value. If interaction with name value is absent fails action. If interaction returns false fails action. Otherwise action succeeds.|
|interact.parameters|string|Optional parameters to use with ''interaction''.|
This is an example of using this action:
===== 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).
^Parameter^Value^Description^
|occupying|''true'', ''false''|Occupier is occupying an interaction spot|
|interact.name|string|Name of interaction|
|interact.has|''true'', ''false''|Has grab spot and interaction with name ''interaction.name'' is present|
|interact.query|''true'', ''false''|Interact with grab spot and test result. Condition is true if grab spot is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).|
|interact.parameters|string|Optional parameters to use with ''interaction.query''.|
|wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled|
This is an example of using this action:
true
====== 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.
^Parameter^Value^Description^
|occupier.occupying|''true'', ''false''|Occupier is occupying an interaction spot|
|occupier.interact.name|string|Name of interaction|
|occupier.interact.has|''true'', ''false''|Has grab spot and interaction with name ''interaction.name'' is present|
|occupier.interact.query|''true'', ''false''|Interact with grab spot and test result. Condition is true if grab spot is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).|
|occupier.interact.parameters|string|Optional parameters to use with ''interaction.query''.|
This is an example of using this condition:
true
occupier.check
====== State Machine Actions ======
Same as [[#behavior_tree_actions|Behavior Tree Actions]].
====== State Machine Conditions ======
Same as [[#behavior_tree_conditions|Behavior Tree Conditions]].
====== State Machine Events ======
This behavior sends these state machine events. If behavior has non-empty identifier replace ''occupier'' with ''occupier(id)''.
===== occupier.claimed =====
Occupier claimed interaction spot.
===== occupier.released =====
Occupier released interaction spot.
====== Required Behaviors ======
This behavior does not required other behaviors to be present.
====== Optional Behaviors ======
* [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use.
* [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorOccupier.html,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:
second
second
value
====== Live Examples ======
In the [[https://github.com/LordOfDragons/deexamples|ExampleApp]] you can find a complete example of using this behavior:
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/InteractionSpotExampleClass.ds|InteractionSpotExampleClass.ds]]: Element class providing an interaction spot the player can use
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/BehaviorInteractToggle.ds|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.
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/PlayerActorClass.ds|PlayerActorClass.ds]]: Player actor class. Uses occupier behavior to safely do interactions.
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/PlayerActionInteractToggle.ds|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.