Table of Contents

,

Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorLookAt

ECBehaviorLookAt

Behavior adding support to actors to know what element they are looking at.

Behavior uses one collider collision test located attached ECBehaviorColliderAI facing forward. If no ECBehaviorColliderAI is present ECBehaviorCollider is used instead.

If ECBehaviorComponent is present and a test bone is set the collision test will be attached to the component bone. This is simple and good solution for FPS type games.

If no component and bone is used and ECBehaviorLocomotion is present then the test parameters will be updated to match the locomotion looking direction.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix lookAt. .

range

Set range in meters. Elements will only be detected this far.

origin

Set origin from where the test ray is cast.

bone

Set bone from where the test ray is cast.

Events

This behavior has these events:

enabledChanged

Enabled changed.

lookAtChanged

Looking at element changed.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorLookAt.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which look-at support.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorColliderAI colliderAI
  public var ECBehaviorLocomotion locomotion
  public var ECBehaviorLookAt lookAt
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    colliderAI = ECBehaviorColliderAI.new(this, collider)
    locomotion = ECBehaviorLocomotion.new(this, colliderAI)
    lookAt = ECBehaviorLookAt.new(this, colliderAI, component, locomotion)
  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='ECBehaviorColliderAI'/>
  <behavior type='ECBehaviorLocomotion'/>
 
  <behavior type='ECBehaviorLookAt'>
    <!-- optional: set collision filter. default value '3:0 1 2 3' which means
                   category BaseGameApp.CollisionFilterBit.actorAI
                   filter BaseGameApp.CollisionFilterBit.geometry,
                          BaseGameApp.CollisionFilterBit.dynamic,
                          BaseGameApp.CollisionFilterBit.actorAI.
                   format is '', 'category' or 'category:filter' where category and filter
                   are a list of bits to set. -->
    <string name='collisionFilter'>3:0 1 2 3</string>
 
    <!-- optional: use component with id instead of empty string -->
    <string name='component'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>Color 1</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorLookAt' id='second'/>
</elementClass>

Live Examples