Class TCreatureResource
Unit
Declaration
type TCreatureResource = class(T3DResource)
Description
Basic abstract resource used by all creatures. Basic creature can walk or fly, has life and can be hurt, can fall down because of gravity and such.
A "resource" is an information shared by all creatures of given type, for example you can have two instances of TCreatureResource
: Werewolf and Knight. Actually, they would have to be instances of one of the TCreatureResource
descendants, like TWalkAttackCreatureResource, as TCreatureResource
is abstract. Using them you can create and place on your your level milions of actual werewolves and knights (for example instances of TWalkAttackCreature). Every werewolf on the level will have potentially different life and state (attacking, walking), but all werewolves will share the same resource, so e.g. all werewolves will use the same dying animation (TWalkAttackCreatureResource.DieAnimation) and dying sound (TCreatureResource.SoundDie).
Note that some of the information stored in resource is only used to initialize new creatures and can be changed later during creature life, for example TCreatureResource.DefaultMaxLife and TCreatureResource.Flying.
Hierarchy
- TObject
- T3DResource
- TCreatureResource
Overview
Fields
![]() |
nested const DefaultDefaultMaxLife = 100.0; |
![]() |
nested const DefaultFlying = false; |
![]() |
nested const DefaultKnockBackDistance = 4.0; |
![]() |
nested const DefaultSoundDieTiedToCreature = true; |
![]() |
nested const DefaultAttackDamageConst = 0.0; |
![]() |
nested const DefaultAttackDamageRandom = 0.0; |
![]() |
nested const DefaultAttackKnockbackDistance = 0.0; |
![]() |
nested const DefaultFallMinHeightToSound = 1.0; |
![]() |
nested const DefaultFallSoundName = 'creature_fall'; |
Methods
![]() |
function RadiusCalculate(const GravityUp: TVector3): Single; virtual; |
![]() |
function FlexibleUp: boolean; virtual; |
![]() |
constructor Create(const AName: string); override; |
![]() |
function CreateCreature( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3; const MaxLife: Single): TCreature; virtual; overload; |
![]() |
function CreateCreature( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3): TCreature; overload; |
![]() |
procedure InstantiatePlaceholder( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3; const NumberPresent: boolean; const Number: Int64); override; |
![]() |
function CreatureClass: TCreatureClass; virtual; abstract; |
![]() |
procedure LoadFromFile(ResourceConfig: TCastleConfig); override; |
![]() |
function Radius(const GravityUp: TVector3): Single; |
Properties
![]() |
property Flying: boolean read FFlying write FFlying default DefaultFlying; |
![]() |
property SoundSuddenPain: TSoundType
read FSoundSuddenPain write FSoundSuddenPain; |
![]() |
property SoundDie: TSoundType
read FSoundDie write FSoundDie; |
![]() |
property SoundDieTiedToCreature: boolean
read FSoundDieTiedToCreature write FSoundDieTiedToCreature
default DefaultSoundDieTiedToCreature; |
![]() |
property DefaultMaxLife: Single
read FDefaultMaxLife write FDefaultMaxLife default DefaultDefaultMaxLife; |
![]() |
property KnockBackDistance: Single
read FKnockBackDistance write FKnockBackDistance
default DefaultKnockBackDistance; |
![]() |
property KnockBackSpeed: Single
read FKnockBackSpeed write FKnockBackSpeed
default TCastleAlive.DefaultKnockBackSpeed; |
![]() |
property CollidesWhenDead: boolean
read FCollidesWhenDead write FCollidesWhenDead default false; |
![]() |
property ScaleMin: Single read FScaleMin write FScaleMin default 1; |
![]() |
property ScaleMax: Single read FScaleMax write FScaleMax default 1; |
![]() |
property AttackDamageConst: Single
read FAttackDamageConst write FAttackDamageConst default DefaultAttackDamageConst; |
![]() |
property AttackDamageRandom: Single
read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom; |
![]() |
property AttackKnockbackDistance: Single
read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance; |
![]() |
property MiddleHeight: Single
read FMiddleHeight write FMiddleHeight
default TCastleTransform.DefaultMiddleHeight; |
![]() |
property FallMinHeightToSound: Single
read FFallMinHeightToSound write FFallMinHeightToSound default DefaultFallMinHeightToSound; |
![]() |
property FallMinHeightToDamage: Single
read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage; |
![]() |
property FallDamageScaleMin: Single
read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin; |
![]() |
property FallDamageScaleMax: Single
read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax; |
![]() |
property FallSound: TSoundType
read FFallSound write FFallSound; |
![]() |
property RadiusOverride: Single
read FRadiusOverride write FRadiusOverride; |
Description
Fields
![]() |
nested const DefaultDefaultMaxLife = 100.0; |
Default value for TCreatureResource.DefaultMaxLife. Yes, it's not a typo, this identifier starts with "DefaultDefault". |
![]() |
nested const DefaultFlying = false; |
![]() |
nested const DefaultKnockBackDistance = 4.0; |
![]() |
nested const DefaultSoundDieTiedToCreature = true; |
![]() |
nested const DefaultAttackDamageConst = 0.0; |
![]() |
nested const DefaultAttackDamageRandom = 0.0; |
![]() |
nested const DefaultAttackKnockbackDistance = 0.0; |
![]() |
nested const DefaultFallMinHeightToSound = 1.0; |
![]() |
nested const DefaultFallSoundName = 'creature_fall'; |
Methods
![]() |
function RadiusCalculate(const GravityUp: TVector3): Single; virtual; |
Sphere radius for collision detection for alive creatures. Must be something <> 0 for collision detection to work. Defining it in the creature resource.xml file (as radius="xxx" attribute on the root <resource> element) overrides the results of this function. |
![]() |
function FlexibleUp: boolean; virtual; |
Can the "up" vector be skewed, that is: not equal to gravity up vector. This is used when creating creature in CreateCreature. The default implementation here returns Override this to return |
![]() |
constructor Create(const AName: string); override; |
![]() |
function CreateCreature( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3; const MaxLife: Single): TCreature; virtual; overload; |
Create the TCreature instance using this resource. Uses TCreature descendant that can best cooperate with this resource, e.g. if this resource has settings for short-range fight, then the TCreature instance will be able to short-range fight. The creature is added to the World, and is owned by World. This is the only way to create TCreature instances. ADirection passed here is normalized, and then used as initial TCreature.Direction value. |
![]() |
function CreateCreature( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3): TCreature; overload; |
![]() |
procedure InstantiatePlaceholder( const ALevel: TAbstractLevel; const APosition, ADirection: TVector3; const NumberPresent: boolean; const Number: Int64); override; |
Instantiate creature placeholder, by calling CreateCreature. |
![]() |
function CreatureClass: TCreatureClass; virtual; abstract; |
![]() |
procedure LoadFromFile(ResourceConfig: TCastleConfig); override; |
![]() |
function Radius(const GravityUp: TVector3): Single; |
Sphere radius for collision detection for alive creatures. Must be something <> 0 for collision detection to work. You can define it in the creature resource.xml file, by setting radius="xxx" attribute on the root <resource> element. If it's not defined (or zero) in resource.xml file, then we use automatically calculated radius using RadiusCalculate, that is adjusted to the bounding box of the animation. This radius is used only for alive creatures, because:
The sphere center is the Middle point ("eye position") of the given creature. If the creature may be affected by gravity then make sure radius is < than PreferredHeight of the creature, see TCastleTransform.PreferredHeight, otherwise creature may get stuck into ground. In short, if you use the default implementations, PreferredHeight is by default MiddleHeight (default 0.5) * bounding box height. Your radius must be smaller for all possible bounding box heights when the creature is not dead. |
Properties
![]() |
property Flying: boolean read FFlying write FFlying default DefaultFlying; |
Flying creatures are not affected by gravity and (in case of TWalkAttackCreatureResource) their move direction is free. For all creatures, TCreature.Gravity (inherited from TCastleTransform.Gravity) is set to For TWalkAttackCreatureResource, additionally Flying allows to move freely, while non-flying creatures are constrained to move (and think about moving) only horizontally. You can always change the Gravity property of a particular creature during it's lifetime, so a creature may start/stop flying during game. For example, this is how you can let your creatures to use jetpack and such. Be careful about creature Radius and MiddleHeight properties in this case, make sure that the values (explicitly set or automatically calculated) are suitable for both flying and non-flying states. |
![]() |
property SoundSuddenPain: TSoundType
read FSoundSuddenPain write FSoundSuddenPain; |
![]() |
property SoundDie: TSoundType
read FSoundDie write FSoundDie; |
![]() |
property SoundDieTiedToCreature: boolean
read FSoundDieTiedToCreature write FSoundDieTiedToCreature
default DefaultSoundDieTiedToCreature; |
See TCreature.Sound3d TiedToCreature parameter docs. You can set this to false if you want SoundDie to last even after the creature object was destroyed. |
![]() |
property DefaultMaxLife: Single
read FDefaultMaxLife write FDefaultMaxLife default DefaultDefaultMaxLife; |
The default MaxLife for creatures of this resource. Note that you can always override it for a particular creature instance. You can use a special creature placeholder with a specific starting life value (see TLevel.Load for placeholders docs, and see https://castle-engine.io/manual_high_level_3d_classes.php about the creature placeholders). Or you can use CreateCreature overloaded version that takes extra MaxLife parameter. So this is only a "suggested" default for MaxLife of this creature. |
![]() |
property KnockBackDistance: Single
read FKnockBackDistance write FKnockBackDistance
default DefaultKnockBackDistance; |
Distance this creature is knocked back when hurt (should reflect the creature weight, how easy it is to push this creature). Will always be multiplied by the knocking distance of the weapon that caused the push (which should reflect the force of the weapon blow), see TItemWeaponResource.AttackKnockbackDistance. Only for TWalkAttackCreature, the final distance the creature is knocked back is capped by the time of the HurtAnimation (HurtAnimation.Duration). When the hurt animation ends, the knockback effect always ends, even if the distance (creature * weapon) indicates it should be knocked further. Otherwise knockback would work on standing creature, which could look bad. This may be changed some day. |
![]() |
property KnockBackSpeed: Single
read FKnockBackSpeed write FKnockBackSpeed
default TCastleAlive.DefaultKnockBackSpeed; |
using deprecated in deprecated |
![]() |
property CollidesWhenDead: boolean
read FCollidesWhenDead write FCollidesWhenDead default false; |
By default dead creatures (corpses) don't collide, this usually looks better. |
![]() |
property ScaleMin: Single read FScaleMin write FScaleMin default 1; |
Minimum scale when spawning, must be <= ScaleMax. When we spawn a creature, we set it's scale to random number in [ |
![]() |
property ScaleMax: Single read FScaleMax write FScaleMax default 1; |
Maximum scale when spawning, must be >= ScaleMin. When we spawn a creature, we set it's scale to random number in [ScaleMin, |
![]() |
property AttackDamageConst: Single
read FAttackDamageConst write FAttackDamageConst default DefaultAttackDamageConst; |
Attack damage. Used by the creatures that actually do some kind of direct attack. For example it is used for short-range attack by TWalkAttackCreatureResource (if TWalkAttackCreatureResource.AttackAnimation defined) and for hit of TMissileCreatureResource. The damage dealt is a random float in the range [ Both |
![]() |
property AttackDamageRandom: Single
read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom; |
Attack damage, see AttackDamageConst for documentation. |
![]() |
property AttackKnockbackDistance: Single
read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance; |
Attack knockback (how far will the victim be pushed back). Used by the creatures that actually do some kind of direct attack. For example it is used for short-range attack by TWalkAttackCreatureResource (if TWalkAttackCreatureResource.AttackAnimation defined) and for hit of TMissileCreatureResource. Must be >= 0. Value equal exactly 0 disables any knockback. |
![]() |
property MiddleHeight: Single
read FMiddleHeight write FMiddleHeight
default TCastleTransform.DefaultMiddleHeight; |
Height of the eyes of the creature, used for various collision detection routines. See TCastleTransform.MiddleHeight for a precise documentation. Game developers can use the RenderDebug variable to easily visualize the bounding sphere (and other things) around resources. The bounding sphere is centered around the point derived from |
![]() |
property FallMinHeightToSound: Single
read FFallMinHeightToSound write FFallMinHeightToSound default DefaultFallMinHeightToSound; |
When creature is falling down, it needs to fall at least the given distance to make a "hurt" sound. |
![]() |
property FallMinHeightToDamage: Single
read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage; |
When creature is falling down, it needs to fall at least the given distance to get some damage from the fall. The amount of damage is determined by FallDamageScaleMin, FallDamageScaleMax. |
![]() |
property FallDamageScaleMin: Single
read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin; |
When creature is falling down (at least for FallMinHeightToDamage distance), it will take a random damage in range [ |
![]() |
property FallDamageScaleMax: Single
read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax; |
When creature is falling down (at least for FallMinHeightToDamage distance), it will take a random damage in range [FallDamageScaleMin, |
![]() |
property FallSound: TSoundType
read FFallSound write FFallSound; |
Sound when falling. The default is the sound named 'creature_fall'. |
![]() |
property RadiusOverride: Single
read FRadiusOverride write FRadiusOverride; |
Radius used for resolving (some) collisions with the alive creature. This can be read from the |
Generated by PasDoc 0.16.0.