Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Class TCreatureResource
Unit
CastleCreatures
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
Overview
Fields
Methods
Properties
Description
Fields
 |
internal const DefaultDefaultMaxLife = 100.0; |
Default value for TCreatureResource.DefaultMaxLife. Yes, it's not a typo, this identifier starts with "DefaultDefault".
|
 |
internal const DefaultFlying = false; |
|
 |
internal const DefaultKnockBackDistance = 4.0; |
|
 |
internal const DefaultSoundDieTiedToCreature = true; |
|
 |
internal const DefaultAttackDamageConst = 0.0; |
|
 |
internal const DefaultAttackDamageRandom = 0.0; |
|
 |
internal const DefaultAttackKnockbackDistance = 0.0; |
|
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 True , which allows creature model to point slightly upward/downward.
Override this to return False if given creature kind for some reason cannot have up vector different. For example, TWalkAttackCreature AI assumes that the non-flying creature is always standing up. For now, non-flying TWalkAttackCreature cannot "stand up" before walking, in case it's up vector gets skewed.
|
 |
constructor Create(const AName: string); override; |
|
 |
function CreateCreature(World: TSceneManagerWorld; 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 it's 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.
|
 |
procedure InstantiatePlaceholder(World: TSceneManagerWorld; const APosition, ADirection: TVector3; const NumberPresent: boolean; const Number: Int64); override; |
Instantiate creature placeholder, by calling CreateCreature.
|
 |
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:
It would cause incorrect results on many dead creatures. Dead creatures usually have very different boxes than alive (tall alive humanoid creature probably has a small flat bounding box when it's lying dead on the ground). So the same radius would not work nicely.
It is not necessary to use sphere bounding volumes for dead creatures. The main advantage of sphere bounding volumes (over box bounding volumes) is for moving (alive) creatures: sphere better avoids getting stuck into obstacles (because an animation can change the bounding box at any moment).
Actually, the results look best when dead creatures don't collide at all.
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 T3D.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 T3D.Gravity) is set to "not Flying" at creation. (Except TMissileCreatureResource, that has special approach to gravity, see TMissileCreatureResource.DirectionFallSpeed.)
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 TGameSceneManager.LoadLevel for placeholders docs, and see http://castle-engine.sourceforge.net/castle-development.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 CollidesWhenDead: boolean
read FCollidesWhenDead write FCollidesWhenDead default false; |
By default dead creatures (corpses) don't collide, this usually looks better.
|
 |
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 MiddleHeight setting and with given creature radius (given in resource.xml, or automatically calculated by TCreatureResource.RadiusCalculate).
|
 |
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 resource.xml file. When zero, the radius is automatically calculated looking at the 3D model bounding box, and taking into account gravity direction, see TCreatureResource.RadiusCalculate.
|
Generated by PasDoc 0.15.0.
|