{{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]] >> **ECBehaviorInteractionSpot** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorInteractionSpot ====== {{youtube>BbP-lMrr0tQ?medium}} Behavior in action (starting at timestamp 1:28) Behavior element behavior adding support to define interaction spot for actors. Defines position and orientation actors or the player have to assume to properly interact with the owner element. This is typically required to line up animations of the actor and the element. Furthermore this allows to track if an actor is occupying the interaction spot. Hence at most one actor can occpuy an interaction spot at each time. Optionally a look-at position can be defined. If the occupier is using [[behavior_conversationactor|ECBehaviorConversationActor]] it can use the look-at position to make actors train their view on a specific point relative to the interaction spot owner element. Elements able to occupy an interaction spot have to use the [[behavior_occupier|ECBehaviorOccupier]] behavior. Both the interaction spot and the occupier have to persist the other behavior. During restoring no notifications are triggered this way. ====== Instance Counts ====== This behavior can be used multiple times on an element to add different interaction prompts. Use the behavior identifier to tell them apart. ====== Element Class Properties ====== Element class properties have the prefix ''interactionSpot.'' or ''interactionSpot(id)''. if id is not empty. ===== position ===== Position relative to owner element the actor or player has to be placed at to interact with the owner element. * Full name: “interactionSpot.position” or “interactionSpot(id).position” * Type: 3-component vector * Default Value: ''(0, 0, 0)'' * Example (*.deeclass) ===== orientation ===== Orientation in euler angles relative to owner element the actor or player has to be placed at to interact with the owner element. * Full name: “interactionSpot.orientation” or “interactionSpot(id).orientation” * Type: 3-component vector * Default Value: ''(0, 0, 0)'' * Example (*.deeclass) ===== lookAt ===== Position to look at while actor or player is approaching the target position. Typically used together with [[behavior_conversationactor|ECBehaviorConversationActor]] to set the Head Look-At playback. Can be null (or empty string with object properties) to not use a look-at. * Full name: “interactionSpot.lookAt” or “interactionSpot(id).lookAt” * Type: 3-component vector * Default Value: ''null'' * Example (*.deeclass) ====== Events ====== ===== spotClaimed ===== Occupier has claimed spot. ===== spotReleased ===== Occupier has release spot. ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''interactionSpot'' with ''interactionSpot(id)''. ===== interactionSpot.update ===== Update interact spot. ^Parameter^Value^Description^ |release| |Release occupied if one interaction spot is not empty.| |interactElement.assign|string|Assign occupying element to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string. Action fails if no element is occupying or interact element behavior is absent| |interact|string|Interact with occupier. 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: ===== interactionSpot.check ===== Check one or more interaction spot parameters. Action succeeds if all parameter value matches their respective interaction spot parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a interaction spot parameter matches (or not). ^Parameter^Value^Description^ |empty|''true'', ''false''|Interaction spot is empty, hence not occupied by an occupier| |interact.name|string|Name of interaction| |interact.has|''true'', ''false''|Has occupier and interaction with name ''interaction.name'' is present| |interact.query|''true'', ''false''|Interact with occupier and test result. Condition is true if occupier 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 ''interactionSpot'' with ''interactionSpot(id)''. ===== interactionSpot.check ===== Check one or more interaction spot parameters. Conditions returns true if all parameter value match their respective interaction spot parameter. This condition is typically used to run an action or sequence of actions as long as interaction spot conditions are true. ^Parameter^Value^Description^ |interactionSpot.empty|''true'', ''false''|Interaction spot is empty, hence not occupied by an occupier| |interactionSpot.interact.name|string|Name of interaction| |interactionSpot.interact.has|''true'', ''false''|Has occupier and interaction with name ''interaction.name'' is present| |interactionSpot.interact.query|''true'', ''false''|Interact with occupier and test result. Condition is true if occupier 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).| |interactionSpot.interact.parameters|string|Optional parameters to use with ''interaction.query''.| This is an example of using this condition: true interactionSpot.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 ''interactionSpot'' with ''interactionSpot(id)''. ===== interactionSpot.claimed ===== Occupier has claimed spot. ===== interactionSpot.released ===== Occupier has release 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_1ECBehaviorInteractionSpot.html,ECBehaviorInteractionSpot~@#. 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 ExampleElementClass extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorInteractionSpot interactionSpot public func new() super("ExampleElement") // Create component and collider to give element a look and feeling component = ECBehaviorComponent.new(this) collider = ECBehaviorCollider.new(this, component) // Create interaction spot in front of the element. Typically actors need // to be rotated by 180 degrees to interact with elements since then the // actor is looking at the front side of the element. // // This behavior is named "use". It is not required to use a name but // it allows to add multiple interaction spots. This can be because the // element has more than one possible interaction or different spots the // same type of interaction can be used. Think of a bench having 3 seats // to sit down. This allows three actors to use the bench but with each // seat occupied by only one actor interactionSpot = ECBehaviorInteractionSpot.new(this, "use") interactionSpot.getPosition().setVector(Vector.new(0, 0, 0.8)) interactionSpot.getOrientation().setVector(Vector.new(0, 180, 0)) interactionSpot.getLookAt().setVector(Vector.new(0, 1.2, 0.2)) end end ====== Behavior Factory ====== Using element class supporting adding behaviors the behavior can be added like this: second second ====== 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.