Class TCastleMoveAttack
Unit
Declaration
type TCastleMoveAttack = class(TCastleBehavior)
Description
Creature that can move around (navigating the 3D world), chasing the enemy, attacking the enemy (by short-range or long-range attack), running away from danger.
Optional dependencies: if present, this behavior will use other behaviors on the same parent:
TCastleSoundSource (to play spatial sounds; this creature is silent otherwise),
TCastleLiving (to account for the fact that current creature may be dead, or badly wounded; if the TCastleLiving is not present, this creature is assumed indestructible.)
Source: src/scene/castlelivingbehaviors_moveattack.inc (line 37).
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleBehavior
- TCastleMoveAttack
Overview
Nested Types
![]() |
TState = (...); |
Fields
Methods
![]() |
procedure SetState(const Value: TState); virtual; |
![]() |
procedure ParentAfterAttach; override; |
![]() |
function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override; |
![]() |
procedure Attack; virtual; |
![]() |
procedure FireMissile; virtual; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
destructor Destroy; override; |
![]() |
function PropertySections(const PropertyName: String): TPropertySections; override; |
![]() |
procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override; |
Properties
![]() |
property State: TState read FState default stateIdle; |
![]() |
property LifeTime: TFloatTime read FLifeTime; |
![]() |
property Enemy: TCastleLiving read FEnemy write SetEnemy; |
![]() |
property SoundAttackHit: TCastleSound read FSoundAttackHit write SetSoundAttackHit; |
![]() |
property SoundAttackStart: TCastleSound read FSoundAttackStart write SetSoundAttackStart; |
![]() |
property AnimationIdle: String read FAnimationIdle write FAnimationIdle stored AnimationIdleStored nodefault; |
![]() |
property AnimationMove: String read FAnimationMove write FAnimationMove stored AnimationMoveStored nodefault; |
![]() |
property AnimationAttack: String read FAnimationAttack write FAnimationAttack stored AnimationAttackStored nodefault; |
![]() |
property AnimationFireMissile: String read FAnimationFireMissile write FAnimationFireMissile stored AnimationFireMissileStored nodefault; |
![]() |
property AnimationDie: String read FAnimationDie write FAnimationDie stored AnimationDieStored nodefault; |
![]() |
property AnimationDieBack: String read FAnimationDieBack write FAnimationDieBack stored AnimationDieBackStored nodefault; |
![]() |
property AnimationHurt: String read FAnimationHurt write FAnimationHurt stored AnimationHurtStored nodefault; |
![]() |
property AttackMinDelay: Single
read FAttackMinDelay write FAttackMinDelay
default DefaultAttackMinDelay; |
![]() |
property AttackMaxDistance: Single
read FAttackMaxDistance write FAttackMaxDistance
default DefaultAttackMaxDistance; |
![]() |
property AttackTime: Single read FAttackTime write FAttackTime
default DefaultAttackTime; |
![]() |
property AttackMaxAngle: Single
read FAttackMaxAngle write FAttackMaxAngle
default DefaultAttackMaxAngle; |
![]() |
property AttackDamage: TCastleDamage read FAttackDamage; |
![]() |
property FireMissileTime: Single
read FFireMissileTime write FFireMissileTime
default DefaultFireMissileTime; |
![]() |
property FireMissileMinDelay: Single
read FFireMissileMinDelay write FFireMissileMinDelay
default DefaultFireMissileMinDelay; |
![]() |
property FireMissileMaxDistance: Single
read FFireMissileMaxDistance write FFireMissileMaxDistance
default DefaultFireMissileMaxDistance; |
![]() |
property FireMissileMaxAngle: Single
read FFireMissileMaxAngle write FFireMissileMaxAngle
default DefaultFireMissileMaxAngle; |
![]() |
property FireMissileHeight: Single
read FFireMissileHeight write FFireMissileHeight
default DefaultFireMissileHeight; |
![]() |
property MoveSpeed: Single read FMoveSpeed write FMoveSpeed
default DefaultMoveSpeed; |
![]() |
property RunAwayLife: Single
read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife; |
![]() |
property RunAwayDistance: Single
read FRunAwayDistance write FRunAwayDistance
default DefaultRunAwayDistance; |
![]() |
property PreferredDistance: Single
read FPreferredDistance write FPreferredDistance
default DefaultPreferredDistance; |
![]() |
property RandomMoveDistance: Single
read FRandomMoveDistance
write FRandomMoveDistance
default DefaultRandomMoveDistance; |
![]() |
property MaxHeightAcceptableToFall: Single
read FMaxHeightAcceptableToFall
write FMaxHeightAcceptableToFall
default DefaultMaxHeightAcceptableToFall; |
![]() |
property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle
default DefaultVisibilityAngle; |
![]() |
property SmellDistance: Single read FSmellDistance write FSmellDistance
default DefaultSmellDistance; |
![]() |
property RemoveDead: Boolean
read FRemoveDead write FRemoveDead default DefaultRemoveDead; |
Description
Nested Types
![]() |
TState = (...); |
|
This item has no description. Values
Source: src/scene/castlelivingbehaviors_moveattack.inc (line 37). | |
Fields
![]() |
nested const DefaultAnimationIdle = 'idle'; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 184). | |
![]() |
nested const DefaultAnimationMove = 'move'; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 185). | |
![]() |
nested const DefaultAnimationAttack = ''; |
|
Default value of AnimationAttack, empty because it is an optional animation. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 186). | |
![]() |
nested const DefaultAnimationFireMissile = ''; |
|
Default value of AnimationFireMissile, empty because it is an optional animation. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 187). | |
![]() |
nested const DefaultAnimationDie = 'die'; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 188). | |
![]() |
nested const DefaultAnimationDieBack = ''; |
|
Default value of AnimationDieBack, empty because it is an optional animation. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 189). | |
![]() |
nested const DefaultAnimationHurt = 'hurt'; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 190). | |
![]() |
nested const DefaultAttackTime = 0.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 192). | |
![]() |
nested const DefaultAttackMinDelay = 2.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 193). | |
![]() |
nested const DefaultAttackMaxDistance = 2.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 194). | |
![]() |
nested const DefaultAttackMaxAngle = Pi / 6; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 195). | |
![]() |
nested const DefaultFireMissileTime = 0.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 197). | |
![]() |
nested const DefaultFireMissileMinDelay = DefaultAttackMinDelay; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 198). | |
![]() |
nested const DefaultFireMissileMaxDistance = 30.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 199). | |
![]() |
nested const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 200). | |
![]() |
nested const DefaultFireMissileHeight = 0.5; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 201). | |
![]() |
nested const DefaultMoveSpeed = 1.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 203). | |
![]() |
nested const DefaultRunAwayLife = 0.3; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 204). | |
![]() |
nested const DefaultRunAwayDistance = 10.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 205). | |
![]() |
nested const DefaultPreferredDistance = DefaultAttackMaxDistance; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 206). | |
![]() |
nested const DefaultRandomMoveDistance = 10.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 207). | |
![]() |
nested const DefaultMaxHeightAcceptableToFall = 1.5; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 208). | |
![]() |
nested const DefaultVisibilityAngle = Pi * 120 / 180; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 209). | |
![]() |
nested const DefaultSmellDistance = 0.0; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 210). | |
![]() |
nested const DefaultRemoveDead = false; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 212). | |
Methods
![]() |
procedure SetState(const Value: TState); virtual; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 154). | |
![]() |
procedure ParentAfterAttach; override; |
|
This item has no description. Showing description inherited from TCastleBehavior.ParentAfterAttach. Called after Parent changed, e.g. at the end of TCastleTransform.AddBehavior. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 155). | |
![]() |
function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override; |
|
This item has no description. Showing description inherited from TCastleBehavior.CanAttachToParent.
Check can this behavior be added to NewParent. When this returns function TCastleBillboard.CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; begin Result := inherited; if not Result then Exit; if NewParent.FindBehavior(TCastleBillboard) <> nil then begin ReasonWhyCannot := 'Only one TCastleBillboard behavior can be added to a given TCastleTransform'; Result := false; end; end; Source: src/scene/castlelivingbehaviors_moveattack.inc (line 156). | |
![]() |
procedure Attack; virtual; |
|
Actually do the attack indicated by AnimationAttack and AttackTime and other AttackXxx properties. This happens in the middle of AnimationAttack, at the time see AttackTime. This can happen only if you defined AnimationAttack (it is <> ''). The default implementation here performs a short range attack, if enemy is still within reach (AttackMaxDistance; even if it was within reach at the start of stateAttack state, the enemy could step back, so we need to check AttackMaxDistance again). The damage and knockback are defined by AttackDamage. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 170). | |
![]() |
procedure FireMissile; virtual; |
|
Actually do the attack indicated by AnimationFireMissile and FireMissileTime and other FireMissileXxx properties. This happens in the middle of AnimationFireMissile, at the time FireMissileTime. This can happen only if you defined AnimationFireMissile (it is <> ''). The default implementation here creates a new missile using FireMissileFactory, if FireMissileFactory is not Source: src/scene/castlelivingbehaviors_moveattack.inc (line 181). | |
![]() |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 214). | |
![]() |
destructor Destroy; override; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 215). | |
![]() |
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
This item has no description. Showing description inherited from TCastleComponent.PropertySections. Section where to show property in the editor. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 216). | |
![]() |
procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override; |
|
This item has no description. Showing description inherited from TCastleBehavior.Update. Continuously occuring event, for various tasks. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 217). | |
Properties
![]() |
property State: TState read FState default stateIdle; |
|
Current state of the creature, automatically changing. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 220). | |
![]() |
property LifeTime: TFloatTime read FLifeTime; |
|
Life, in seconds. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 223). | |
![]() |
property Enemy: TCastleLiving read FEnemy write SetEnemy; |
|
Enemy that is being chased and attacked by this creature. May be Source: src/scene/castlelivingbehaviors_moveattack.inc (line 227). | |
![]() |
property SoundAttackHit: TCastleSound read FSoundAttackHit write SetSoundAttackHit; |
|
Sound played when short-range attack hits. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 230). | |
![]() |
property SoundAttackStart: TCastleSound read FSoundAttackStart write SetSoundAttackStart; |
|
Played at the start of attack animation, that is when entering stateAttack state. To play a sound when the actual hit happens (at AttackTime) see SoundAttackHit. This is a sound name from sound repository (see https://castle-engine.io/manual_sound.php). None by default. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 239). | |
![]() |
property AnimationIdle: String read FAnimationIdle write FAnimationIdle stored AnimationIdleStored nodefault; |
|
An animation of being idle (standing / floating in place). Will be played in a loop. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 243). | |
![]() |
property AnimationMove: String read FAnimationMove write FAnimationMove stored AnimationMoveStored nodefault; |
|
Animation of moving, will be played in a loop. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 246). | |
![]() |
property AnimationAttack: String read FAnimationAttack write FAnimationAttack stored AnimationAttackStored nodefault; |
|
An animation of short-range attacking. Optional, it may be '' if creature doesn't make short-range attack. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 250). | |
![]() |
property AnimationFireMissile: String read FAnimationFireMissile write FAnimationFireMissile stored AnimationFireMissileStored nodefault; |
|
Firing missile animation. Optional, it may be '' if creature doesn't fire missiles. You can always override TCastleMoveAttack.FireMissile to do pretty much anything you want, and this way treat this as an "alternate attack", not necessarily firing a missile. It's not really required to actually fire a missile — it's only what happens at the default TCastleMoveAttack.FireMissile implementation. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 260). | |
![]() |
property AnimationDie: String read FAnimationDie write FAnimationDie stored AnimationDieStored nodefault; |
|
An animation of dying. Dying animation is not displayed in a loop, after it runs it's duration we constantly show the final frame. Unless you set RemoveDead to Source: src/scene/castlelivingbehaviors_moveattack.inc (line 268). | |
![]() |
property AnimationDieBack: String read FAnimationDieBack write FAnimationDieBack stored AnimationDieBackStored nodefault; |
|
Alternative optional (may be '') dying animation, used when the creature is killed by hitting it in the back. This may be useful if you want your creature to fall face-down when killed from the back or face-up when killed from the front. If this is defined, then AnimationDie is only used when creature is killed by hitting it from the front. The direction of last hit is taken from LastHurtDirection. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 276). | |
![]() |
property AnimationHurt: String read FAnimationHurt write FAnimationHurt stored AnimationHurtStored nodefault; |
|
Animation when the creature will be hurt. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 279). | |
![]() |
property AttackMinDelay: Single
read FAttackMinDelay write FAttackMinDelay
default DefaultAttackMinDelay; |
|
Minimum delay between one attack and the other, in seconds. Note that the duration of AnimationAttack also limits how often creature can do an attack (so e.g. setting this to 0.0 doesn't mean that creature can constantly attack, if AnimationAttack takes 1 second then at least this 1 second will have to pass between actual attack hits). Source: src/scene/castlelivingbehaviors_moveattack.inc (line 286). | |
![]() |
property AttackMaxDistance: Single
read FAttackMaxDistance write FAttackMaxDistance
default DefaultAttackMaxDistance; |
|
Maximum distance between enemy and creature to allow creature to start attack. The distance is measured between enemy (see TCastleMoveAttack.Enemy) and current creature Middle (see TCastleTransform.Middle) points. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 294). | |
![]() |
property AttackTime: Single read FAttackTime write FAttackTime
default DefaultAttackTime; |
|
The time point within AnimationAttack at which the short-range attack happens. When exactly happens depends on the virtual TCastleMoveAttack.Attack method implementation, in the base TCastleMoveAttack it is a short-range attack. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 303). | |
![]() |
property AttackMaxAngle: Single
read FAttackMaxAngle write FAttackMaxAngle
default DefaultAttackMaxAngle; |
|
Since most of the creatures will have their weapon on their front (teeth, shooting hands, claws, whatever), they can attack enemy only when they are facing the enemy. More precisely, the attack is allowed to start only when the angle between current creature Direction and the vector from creature's Middle to the enemy's Middle (see TCastleTransform.Middle) is <= This is in radians. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 316). | |
![]() |
property AttackDamage: TCastleDamage read FAttackDamage; |
|
Attack damage. Used by the creatures that do short-range attack (when AnimationAttack is set). Source: src/scene/castlelivingbehaviors_moveattack.inc (line 323). | |
![]() |
property FireMissileTime: Single
read FFireMissileTime write FFireMissileTime
default DefaultFireMissileTime; |
|
The time (in seconds) since the AnimationFireMissile start when we actually spawn a missile. By default zero, which means that we spawn the missile right when AnimationFireMissile starts. Must be < than the AnimationFireMissile duration, otherwise we will never reach tthis time and missile will never be fired. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 330). | |
![]() |
property FireMissileMinDelay: Single
read FFireMissileMinDelay write FFireMissileMinDelay
default DefaultFireMissileMinDelay; |
|
Minimum delay (in seconds) between firing of the missiles. The missile will not be fired if a previous missile was fired within last Source: src/scene/castlelivingbehaviors_moveattack.inc (line 338). | |
![]() |
property FireMissileMaxDistance: Single
read FFireMissileMaxDistance write FFireMissileMaxDistance
default DefaultFireMissileMaxDistance; |
|
Maximum distance to the enemy to make firing missiles sensible. The creature will only fire the missile if enemy is within this distance. The creature will also try to shorten distance to the enemy, to get within this distance. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 346). | |
![]() |
property FireMissileMaxAngle: Single
read FFireMissileMaxAngle write FFireMissileMaxAngle
default DefaultFireMissileMaxAngle; |
|
Maximum angle (in radians) between current direction and the direction toward enemy to make firing missiles sensible. The creature will only fire the missile if enemy is within a cone of this angle. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 353). | |
![]() |
property FireMissileHeight: Single
read FFireMissileHeight write FFireMissileHeight
default DefaultFireMissileHeight; |
|
Height (between Position and Middle, usually: legs and eyes) of the fired missile (see FireMissileFactory). Source: src/scene/castlelivingbehaviors_moveattack.inc (line 359). | |
![]() |
property MoveSpeed: Single read FMoveSpeed write FMoveSpeed
default DefaultMoveSpeed; |
|
The moving speed: how much Direction vector will be scaled when moving in csWalk. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 365). | |
![]() |
property RunAwayLife: Single
read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife; |
|
Portion of life and distance when the creature decides it's best to run away from the enemy. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 375). | |
![]() |
property RunAwayDistance: Single
read FRunAwayDistance write FRunAwayDistance
default DefaultRunAwayDistance; |
|
This item has no description. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 377). | |
![]() |
property PreferredDistance: Single
read FPreferredDistance write FPreferredDistance
default DefaultPreferredDistance; |
|
The preferred distance between enemy and the creature. The creature will try to walk closer to the enemy if the distance is larger. (If you want to make the creature to also walk father from the enemy when necessary, then set RunAwayLife and RunAwayDistance.) This should be <= AttackMaxDistance or FireMissileMaxDistance, if you hope to actually perform a short-range or firing missile attack. The creature can attack enemy from AttackMaxDistance or fire missile from FireMissileMaxDistance, but it will walk closer to the enemy if possible — until the distance is Source: src/scene/castlelivingbehaviors_moveattack.inc (line 393). | |
![]() |
property RandomMoveDistance: Single
read FRandomMoveDistance
write FRandomMoveDistance
default DefaultRandomMoveDistance; |
|
Distance to point to move to, when creature wanders aimlessly unable to reach the target, but also wanting to move somewhere. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 399). | |
![]() |
property MaxHeightAcceptableToFall: Single
read FMaxHeightAcceptableToFall
write FMaxHeightAcceptableToFall
default DefaultMaxHeightAcceptableToFall; |
|
When considering possible movement, creature is OK to fall down from this height. It should be small enough to not let creature to jump into chasms, but also large enough to enable creature to get down e.g. stairs. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 407). | |
![]() |
property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle
default DefaultVisibilityAngle; |
|
Creature sees other things (like enemies) only within a cone of this angle. This way, the creature only looks forward, and you can sneak upon a creature from the back. Simply set this to >= 2 * Pi to remove this limit. Note that the creature also becomes aware of the enemy when it is hurt by a direct attack, regardless of Creature can also smell others, see SmellDistance. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 423). | |
![]() |
property SmellDistance: Single read FSmellDistance write FSmellDistance
default DefaultSmellDistance; |
|
Creature smells other things (like enemies) within a sphere of this radius. This allows to detect enemy regardless of which direction the creature is facing, regardless of whether there is a line of sight to the enemy, regardless if enemy is moving. This is quite powerful ability to detect enemies, if you set this to something large (by default it's zero). Detecting enemies allows to more accurately/faster attack them and/or run away from them. Note: If you want the creature to nicely run from behind the corner, be sure to setup good sectors/waypoints in your level. Source: src/scene/castlelivingbehaviors_moveattack.inc (line 438). | |
![]() |
property RemoveDead: Boolean
read FRemoveDead write FRemoveDead default DefaultRemoveDead; |
|
Should dead creature instances be automatically freed and thus removed from the viewport. The default Source: src/scene/castlelivingbehaviors_moveattack.inc (line 444). | |
Generated by PasDoc 0.17.0.snapshot.


