User Tools

Site Tools


dragengine:modules:dragonscript:behavior_playercontrollable

ECBehaviorPlayerControllable

Behavior element behavior adding player controlling support to actor.

Actors with this behavior can become the player controlled actor. Requires an instance of ECBehaviorPlayerControllable.Tracker to be assigned. The instance keeps track of the active player actor and is typically stored globally in the game. BaseGameApp provides such an instance for easy use.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix playerControllable. .

Events

playerTakesControl

Became active player actor.

playerReleasesControl

Ceased being active player actor.

Conversation Commands

playerControllable

playerControllable takeControl

Make actor become the active player actor.

Conversation Conditions

playerControllable

playerControllable isPlayerControlled

Actor is the active player actor.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

playerControllable.update

Update player controllable.

ParameterValueDescription
takeControl Make player take control of actor

This is an example of using this action:

<action name='playerControllable.update'>
  <parameter name='takeControl'/>
</action>

playerControllable.check

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

ParameterValueDescription
playerControlledtrue, falseActor is controlled by player
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:

<sequence>
  <action name='playerControllable.check'>
    <parameter name='playerControlled'>true</parameter>
  </action>
  <!-- actions here run only if actor is controlled by player -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present.

playerControllable.check

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

ParameterValueDescription
playerControllable.playerControlledtrue, falseActor is controlled by player

This is an example of using this condition:

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

State Machine Actions

State Machine Conditions

State Machine Events

This behavior send no events to state machine.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorPlayerControllable.

Since DragonScript Module Version 1.0

Use Cases

  • Allow element to be controlled by player.

Element Class Example

This example defines an element which can be controlled by the player.

class MyElement extends BehaviorElementClass
  public var ECBehaviorPlayerControllable playerControllable
  func new()
    playerControllable = ECBehaviorPlayerControllable.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='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorPlayerControllable'>
    <!-- optional: use BaseGameApp player controlled actor.
                   game can add more supported values. default is 'default' -->
    <string name='playerControlledActor'>default</string>
 
    <!-- 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>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_playercontrollable.txt · Last modified: 2025/05/11 13:43 by dragonlord