Class TWalkAttackCreatureResource
Unit
CastleCreatures
Declaration
type TWalkAttackCreatureResource = class(TCreatureResource)
Description
Creature with smart walking and attacking intelligence. May stand still (idle), walk, attack, fire missiles, and die.
Tracks the enemy (remembers last seen enemy 3D position, walks/flies to it, possibly through sectors/waypoints — so it can pass through narrow doors in a labyrinth or walk over a narrow bridge). Attacks the enemy from the right distance (a short-range attack) and/or shoots a missile (adds a missile to the 3D world). Runs away from the enemy (when he's too close and/or our health is low).
There are a lot of settings to achieve particular behavior, e.g. cowardly/brave, offensive/defensive, melee/ranged, etc.
Hierarchy
Overview
Fields
Methods
Properties
Description
Fields
 |
nested const DefaultMoveSpeed = 10.0; |
|
 |
nested const DefaultMinLifeLossToHurt = 0.0; |
|
 |
nested const DefaultChanceToHurt = 1.0; |
|
 |
nested const DefaultMaxHeightAcceptableToFall = 1.5; |
|
 |
nested const DefaultRandomWalkDistance = 10.0; |
|
 |
nested const DefaultRemoveDead = false; |
|
 |
nested const DefaultPreferredDistance = 2.0; |
|
 |
nested const DefaultRunAwayLife = 0.3; |
|
 |
nested const DefaultRunAwayDistance = 10.0; |
|
 |
nested const DefaultVisibilityAngle = Pi * 120 / 180; |
|
 |
nested const DefaultSmellDistance = 0.0; |
|
 |
nested const DefaultAttackTime = 0.0; |
|
 |
nested const DefaultAttackMinDelay = 2.0; |
|
 |
nested const DefaultAttackMaxAngle = Pi / 6; |
|
 |
nested const DefaultFireMissileTime = 0.0; |
|
 |
nested const DefaultFireMissileMaxDistance = 30.0; |
|
 |
nested const DefaultFireMissileHeight = 0.5; |
|
Methods
 |
function FlexibleUp: boolean; override; |
|
 |
constructor Create(const AName: string); override; |
|
Properties
 |
property IdleAnimation: T3DResourceAnimation read FIdleAnimation; |
An animation of standing still (being idle). Will be played in a loop, so for best look make sure that the beginning and end match.
|
 |
property IdleToWalkAnimation: T3DResourceAnimation read FIdleToWalkAnimation; |
An animation when creature changes from standing still to walking. Optional.
For best look: It's beginnig should glue with the end of IdleAnimation, it's ending should glue with beginning of WalkAnimation.
|
 |
property WalkAnimation: T3DResourceAnimation read FWalkAnimation; |
An animation of walking. Will be played in a loop, so for best look make sure that the beginning and end match.
|
 |
property AttackAnimation: T3DResourceAnimation read FAttackAnimation; |
An animation of short-range attacking. Optional.
For best look: Beginning and end of it should roughly glue with (any) frame of WalkAnimation and IdleAnimation.
Design notes: I used to have here property like AttacksWhenWalking for the creature, to indicate whether creature changes state like "csWalk -> csAttack -> csWalk" or "csIdle -> csAttack -> csIdle". But this wasn't good. Intelligent creature sometimes attacks when walking (e.g. if it just made the distance to the enemy closer) or when standing (when the distance was already close enough). And after performing the attack, the creature doesn't need to go back to the original state before the attack.
|
 |
property FireMissileAnimation: T3DResourceAnimation read FFireMissileAnimation; |
Firing missile animation. Optional. Similar rules like AttackAnimation, but here the "highlight" is not directly hurting enemy, but firing a new creature (missile).
You can always override TWalkAttackCreature.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 TWalkAttackCreature.FireMissile implementation, and it happens only if FireMissileName is not empty.
|
 |
property DieAnimation: T3DResourceAnimation read FDieAnimation; |
An animation of dying.
Dying animation is not displayed in a loop, after it runs it's duration we constantly show the final frame, at the TCreature instance will keep existing on the level. Unless you set RemoveDead to True , then the dead creature will be completely removed from the level.
For best look: Beginning should roughly glue with any point of the idle/attack/walk animations.
|
 |
property DieBackAnimation: T3DResourceAnimation read FDieBackAnimation; |
An optional 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 DieAnimation is only used when creature is killed by hitting it from the front. The direction of last hit is taken from LastHurtDirection.
For best look: Just like DieAnimation, beginning should roughly glue with any point of the idle/attack/walk animations.
|
 |
property HurtAnimation: T3DResourceAnimation read FHurtAnimation; |
Animation when the creature will be hurt. Beginning and end should *more-or-less* look like any point of the idle/attack/walk animations.
|
 |
property MoveSpeed: Single read FMoveSpeed write FMoveSpeed
default DefaultMoveSpeed; |
The moving speed: how much Direction vector will be scaled when moving in csWalk.
|
 |
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 PreferredDistance .
|
 |
property AttackMinDelay: Single
read FAttackMinDelay write FAttackMinDelay
default DefaultAttackMinDelay; |
Minimum delay between one attack and the other, in seconds. Note that the duration of AttackAnimation 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 AttackAnimation takes 1 second then at least this 1 second will have to pass between actual attack hits).
|
 |
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 <= AttackMaxAngle .
This is in radians.
|
 |
property AttackSoundHit: TSoundType
read FAttackSoundHit write FAttackSoundHit; |
Sound played when short-range attack hits. None (stNone) by default.
|
 |
property AttackSoundStart: TSoundType
read FAttackSoundStart write FAttackSoundStart; |
Played at the start of attack animation, that is when entering csAttack state. To play a sound when the actual hit happens (at AttackTime) see AttackSoundHit. None (stNone) by default.
|
 |
property FireMissileTime: Single
read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime; |
The time (in seconds) since the FireMissileAnimation start when we actually spawn a missile. By default zero, which means that we spawn the missile right when FireMissileAnimation starts. Must be < than the FireMissileAnimation 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 FireMissileMinDelay seconds. (Even if all other conditions for firing the missile are satisfied.)
|
 |
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 FireMissileName: string
read FFireMissileName write FFireMissileName; |
Name of the creature to fire as missile, at AttackTime during AttackAnimation. Leave empty to not fire any missile.
|
 |
property FireMissileHeight: Single
read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight; |
Height (between Position and Middle, usually: legs and eyes) of the fired missile (see FireMissileName).
|
 |
property FireMissileSound: TSoundType
read FFireMissileSound write FFireMissileSound; |
Sound played when missile is fired, see FireMissileName. None (stNone) by default.
|
 |
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. RunAwayLife is expressed as a fraction of MaxLife. We run if our Life <= MaxLife * RunAwayLife and the distance to the (last seen) enemy is < RunAwayDistance. Set RunAwayLife = 1 to make the creature always try to keep a safe distance from the enemy.
|
 |
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 VisibilityAngle . This way if you sneak and attack a creature from the back, it will turn around and fight you.
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 MinLifeLossToHurt: Single
read FMinLifeLossToHurt write FMinLifeLossToHurt
default DefaultMinLifeLossToHurt; |
When creature is wounded for more than MaxLife * MinLifeLossToHurt points and moreover Random < ChanceToHurt then creature will change to csHurt state and be knocked back. Changing to csHurt state means that any other state will be interrupted (e.g. enemy can interrupt creature's attack this way if AttackTime > 0).
It's expected that "tougher" creatures will have MinLifeLossToHurt somewhat higher than DefaultMinLifeLossToHurt and ChanceToHurt significantly lower than DefaultChanceToHurt.
|
 |
property RemoveDead: boolean
read FRemoveDead write FRemoveDead default DefaultRemoveDead; |
|
Generated by PasDoc 0.16.0.