User Tools

Site Tools


dragengine:modules:dragonscript:behavior_interactionspot

ECBehaviorInteractionSpot

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 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 ECBehaviorOccupier behavior. Both the interaction spot and the occupier have to persist the other behavior. During restoring no notifications are triggered this way.

Behavior in action (starting at timestamp 1:28)

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. Format used with object properties (string): “x y z”
  • Default Value: (0, 0, 0)
  • Example (*.deeclass)
    <vector name='interactionSpot.position' x='0' y='-1' z='0.5'/>

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. Format used with object properties (string): “x y z”
  • Default Value: (0, 0, 0)
  • Example (*.deeclass)
    <vector name='interactionSpot.orientation' x='0' y='180' z='0'/>

lookAt

Position to look at while actor or player is approaching the target position. Typically used together with 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. Format used with object properties (string): “x y z”
  • Default Value: null
  • Example (*.deeclass)
    <vector name='interactionSpot.position' x='0' y='0.2' z='0.5'/>

Required Behaviors

This behavior does not required other behaviors to be present.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does support element class to be persistable (setPersistable). Saves ECBehaviorOccupier if present.

API Documentation

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

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_interactionspot.txt · Last modified: 2024/03/14 16:54 by dragonlord