{{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]] >> **ECBehaviorProjectToGround**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorProjectToGround ======
Behavior element behavior adding project to ground support for actor AI.
Adds TouchSensor. The touch sensor is used to improve performance and requires a shape large enough to enclose the ECBehaviorColliderAI or ECBehaviorCollider (whichever is present) along all the up and down projection range. The touch sensor is attached to collider. The touch sensor uses the collision filter from collider.
To use this behavior add it to an actor. The behavior will run during postThink() and projects the actor position down to the ground if enabled. The grounded position is stored and can then be retrieved to work with. By default the behavior is set to automatically apply the grounded position to the actor. This behavior can be desibled for custome project to ground handling.
====== Instance Counts ======
This behavior can be used only once on an element.
====== Element Class Properties ======
Element class properties have the prefix ''projectToGround.'' .
===== applyToActor =====
Set apply projected position automatically to actor during postThink(). If disabled actor actions have to use getGroundedPosition() to place the actor.
* Full name: ''projectToGround.applyToActor''
* Type: boolean
* Default Value: true
* Example (*.deeclass) false
====== Events ======
This behavior has these events:
===== enabledChanged =====
Enabled changed.
===== touchesGroundChanged =====
Actor switched between touching ground and not touching ground.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present.
===== projectToGround.check =====
Check one or more project to ground parameters. Action succeeds if all parameter value matches their respective project to ground parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a project to ground parameter matches (or not).
^Parameter^Value^Description^
|enabled|''true'', ''false''|Project to ground is enabled|
|ground|''true'', ''false''|Touching ground|
|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.
===== projectToGround.check =====
Check one or more project to ground parameters. Conditions returns true if all parameter value match their respective project to ground parameter. This condition is typically used to run an action or sequence of actions as long as project to ground conditions are true.
^Parameter^Value^Description^
|projectToGround.enabled|''true'', ''false''|Project to ground is enabled|
|projectToGround.ground|''true'', ''false''|Touching ground|
This is an example of using this condition:
true
projectToGround.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.
===== projectToGround.enabled =====
Project to ground has been enabled.
===== projectToGround.disabled =====
Project to ground has been disabled.
===== projectToGround.touch =====
Element is touching ground while previously has not been touching ground.
===== projectToGround.noTouch =====
Element is not touching ground while previously has been touching ground.
====== Required Behaviors ======
* [[behavior_colliderai|ECBehaviorColliderAI]] or [[behavior_collider|ECBehaviorCollider]]
====== 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_1ECBehaviorProjectToGround.html,ECBehaviorProjectToGround~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Project actor down to ground if in reach.
====== Element Class Example ======
This example defines an element which project to ground support.
class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorColliderAI colliderAI
public var ECBehaviorProjectToGround projectToGround
func new()
component = ECBehaviorComponent.new(this, null)
collider = ECBehaviorCollider.new(this, component)
colliderAI = ECBehaviorColliderAI.new(this, collider)
projectToGround = ECBehaviorProjectToGround.new(this, colliderAI)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
second
second
false
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]