{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorLookAt** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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 [[behavior_colliderai|ECBehaviorColliderAI]] is present [[behavior_collider|ECBehaviorCollider]] is used instead. If [[behavior_component|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 [[behavior_locomotion|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. * Full name: ''lookAt.range'' * Type: float * Default Value: 2 * Restriction: At least 0 * Example (*.deeclass) 3 ===== origin ===== Set origin from where the test ray is cast. * Full name: ''lookAt.origin'' * Type: 3-component float vector * Default Value: (0,1.6,0) * Example (*.deeclass) ===== bone ===== Set bone from where the test ray is cast. * Full name: ''lookAt.bone'' * Type: string * Default Value: empty string * Example (*.deeclass) head ====== Events ====== This behavior has these events: ===== enabledChanged ===== Enabled changed. ===== lookAtChanged ===== Looking at element changed. ====== Required Behaviors ====== This behavior requires no other behaviors. ====== Optional Behaviors ====== * [[behavior_colliderai|ECBehaviorColliderAI]]: Cast test ray relative to collider * [[behavior_collider|ECBehaviorCollider]]: Cast test ray relative to collider * [[behavior_component|ECBehaviorComponent]]: Cast test ray from bone from component * [[behavior_locomotion|ECBehaviorLocomotion]]: Use lcomotion looking state to direct test ray cast direction ====== Persistency ====== This behavior does not required element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorLookAt.html,ECBehaviorLookAt~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Detect what element the player or an NPC is looking at. ====== 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: 3:0 1 2 3 second Color 1 ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]