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.)
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
|
Fields
nested const DefaultAnimationIdle = 'idle'; |
|
This item has no description. |
nested const DefaultAnimationMove = 'move'; |
|
This item has no description. |
nested const DefaultAnimationAttack = ''; |
|
Default value of AnimationAttack, empty because it is an optional animation. |
nested const DefaultAnimationFireMissile = ''; |
|
Default value of AnimationFireMissile, empty because it is an optional animation. |
nested const DefaultAnimationDie = 'die'; |
|
This item has no description. |
nested const DefaultAnimationDieBack = ''; |
|
Default value of AnimationDieBack, empty because it is an optional animation. |
nested const DefaultAnimationHurt = 'hurt'; |
|
This item has no description. |
nested const DefaultAttackTime = 0.0; |
|
This item has no description. |
nested const DefaultAttackMinDelay = 2.0; |
|
This item has no description. |
nested const DefaultAttackMaxDistance = 2.0; |
|
This item has no description. |
nested const DefaultAttackMaxAngle = Pi / 6; |
|
This item has no description. |
nested const DefaultFireMissileTime = 0.0; |
|
This item has no description. |
nested const DefaultFireMissileMinDelay = DefaultAttackMinDelay; |
|
This item has no description. |
nested const DefaultFireMissileMaxDistance = 30.0; |
|
This item has no description. |
nested const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle; |
|
This item has no description. |
nested const DefaultFireMissileHeight = 0.5; |
|
This item has no description. |
nested const DefaultMoveSpeed = 1.0; |
|
This item has no description. |
nested const DefaultRunAwayLife = 0.3; |
|
This item has no description. |
nested const DefaultRunAwayDistance = 10.0; |
|
This item has no description. |
nested const DefaultPreferredDistance = DefaultAttackMaxDistance; |
|
This item has no description. |
nested const DefaultRandomMoveDistance = 10.0; |
|
This item has no description. |
nested const DefaultMaxHeightAcceptableToFall = 1.5; |
|
This item has no description. |
nested const DefaultVisibilityAngle = Pi * 120 / 180; |
|
This item has no description. |
nested const DefaultSmellDistance = 0.0; |
|
This item has no description. |
nested const DefaultRemoveDead = false; |
|
This item has no description. |
Methods
procedure SetState(const Value: TState); virtual; |
|
This item has no description. |
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. |
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; |
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. |
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 |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
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. |
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. |
Properties
property State: TState read FState default stateIdle; |
|
Current state of the creature, automatically changing. |
property LifeTime: TFloatTime read FLifeTime; |
|
Life, in seconds. |
property Enemy: TCastleLiving read FEnemy write SetEnemy; |
|
Enemy that is being chased and attacked by this creature. May be |
property SoundAttackHit: TCastleSound read FSoundAttackHit write SetSoundAttackHit; |
|
Sound played when short-range attack hits. |
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. |
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. |
property AnimationMove: String read FAnimationMove write FAnimationMove stored AnimationMoveStored nodefault; |
|
Animation of moving, will be played in a loop. |
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. |
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 |
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. |
property AnimationHurt: String read FAnimationHurt write FAnimationHurt stored AnimationHurtStored nodefault; |
|
Animation when the creature will be hurt. |
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). |
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. |
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. |
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. |
property AttackDamage: TCastleDamage read FAttackDamage; |
|
Attack damage. Used by the creatures that do short-range attack (when AnimationAttack is set). |
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. |
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 |
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. |
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. |
property FireMissileHeight: Single
read FFireMissileHeight write FFireMissileHeight
default DefaultFireMissileHeight; |
|
Height (between Position and Middle, usually: legs and eyes) of the fired missile (see FireMissileFactory). |
property MoveSpeed: Single read FMoveSpeed write FMoveSpeed
default DefaultMoveSpeed; |
|
The moving speed: how much Direction vector will be scaled when moving in csWalk. |
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. |
property RunAwayDistance: Single
read FRunAwayDistance write FRunAwayDistance
default DefaultRunAwayDistance; |
|
This item has no description. |
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 |
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. |
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. |
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. |
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. |
property RemoveDead: Boolean
read FRemoveDead write FRemoveDead default DefaultRemoveDead; |
|
Should dead creature instances be automatically freed and thus removed from the viewport. The default |
Generated by PasDoc 0.16.0-snapshot.