Class TCastleThirdPersonNavigation
Unit
CastleThirdPersonNavigation
Declaration
type TCastleThirdPersonNavigation = class(TCastleMouseLookNavigation)
Description
3rd-person camera navigation. Create an instance of this and assign it to TCastleViewport.Navigation to use. Be sure to also assign Avatar. Call Init once the parameters that determine initial camera location are all set.
Turn on TCastleNavigation.MouseLook to allow user to move the mouse to orbit with the camera around the avatar. When AimAvatar is aaNone (default), it allows to look at the avatar easily from any side (e.g. you can then see avatar's face easily). When AimAvatar is aaHorizontal or aaFlying, rotating allows to point the avatar at the appropriate direction.
Using keys AWSD and arrows you can move and rotate the avatar, and the camera will follow.
Using the mouse wheel you can get closer / further to the avatar.
See also the news post with demo movie about this component: https://castle-engine.io/wp/2020/06/29/third-person-navigation-with-avatar-component-in-castle-game-engine/
Hierarchy
Overview
Fields
Methods
Properties
Description
Fields
|
nested const DefaultInitialHeightAboveTarget = 1.0; |
|
|
nested const DefaultDistanceToAvatarTarget = 4.0; |
|
|
nested const DefaultAvatarRotationSpeed = 10; |
|
|
nested const DefaultAvatarTarget: TVector3 = (X: 0; Y: 2; Z: 0); |
|
|
nested const DefaultCameraSpeed = 10; |
|
|
nested const DefaultMoveSpeed = 1.0; |
|
|
nested const DefaultCrouchSpeed = 0.5; |
|
|
nested const DefaultRunSpeed = 2.0; |
|
|
nested const DefaultRotationSpeed = Pi * 150 / 180; |
|
|
nested const DefaultCameraDistanceChangeSpeed = 1; |
|
|
nested const DefaultMinDistanceToAvatarTarget = 0.5; |
|
|
nested const DefaultMaxDistanceToAvatarTarget = 10; |
|
|
nested const DefaultAnimationIdle = 'idle'; |
|
|
nested const DefaultAnimationRotate = 'rotate'; |
|
|
nested const DefaultAnimationWalk = 'walk'; |
|
|
nested const DefaultAnimationRun = 'run'; |
|
|
nested const DefaultAnimationCrouch = 'crouch'; |
|
|
nested const DefaultAnimationCrouchIdle = 'crouch_idle'; |
|
|
nested const DefaultAnimationCrouchRotate = 'crouch_rotate'; |
|
Methods
|
procedure ProcessMouseLookDelta(const Delta: TVector2); override; |
|
|
constructor Create(AOwner: TComponent); override; |
|
|
destructor Destroy; override; |
|
|
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
|
Properties
|
property AvatarTarget: TVector3 read FAvatarTarget write FAvatarTarget; |
Translation, from the avatar origin, to the "target" of the avatar where camera looks at. This is usually head, and this vector should just describe the height of head above the ground. By default this is DefaultAvatarTarget = (0, 2, 0).
|
|
property Input_CameraFurther: TInputShortcut read FInput_CameraFurther; |
|
|
property MouseLookHorizontalSensitivity; |
|
|
property MouseLookVerticalSensitivity; |
|
|
property InvertVerticalMouseLook; |
|
|
property CameraFollows: Boolean read FCameraFollows write SetCameraFollows default true; |
Does camera follow the avatar, by default yes.
When this is False , camera remains unchanged by anything here (avatar movement/rotations, mouse look, even by calling Init). Some properties of this then are meaningless (e.g. DistanceToAvatarTarget).
However, all the inputs to control the avatar continue to work.
|
|
property Avatar: TCastleScene read FAvatar write SetAvatar; |
Avatar scene, that is animated, moved and rotated when this navigation changes. This navigation component will just call Avatar.AutoAnimation := 'xxx' when necessary. Currently we require the following animations to exist: walk, idle.
When AvatarHierarchy is Nil , then Avatar is directly moved and rotated to move avatar . Otherwise, AvatarHierarchy is moved, and Avatar should be inside AvatarHierarchy.
This scene should be part of TCastleViewport.Items to make this navigation work, in particular when you call Init.
|
|
property AvatarHierarchy: TCastleTransform read FAvatarHierarchy write SetAvatarHierarchy; |
Optional avatar hierarchy that is moved and rotated when this navigation changes. When this is Nil , we just move and rotate the Avatar. When this is non-nil, then we only move and rotate this AvatarHierarchy .
If AvatarHierarchy is non-nil, then it should contain Avatar as a child. AvatarHierarchy can even be equal to Avatar (it is equivalent to just leaving AvatarHierarchy as Nil ).
This object should be part of TCastleViewport.Items to make this navigation work, in particular when you call Init.
|
|
property AvatarRotationSpeed: Single read FAvatarRotationSpeed write FAvatarRotationSpeed
default DefaultAvatarRotationSpeed; |
When AimAvatar, this is avatar's rotation speed (in radians per second). Should make avatar rotation "catch up" (with some delay after camera rotation.
|
|
property CameraSpeed: Single read FCameraSpeed write FCameraSpeed
default DefaultCameraSpeed; |
Camera position tracks the desired position with given speed (in units per second). This makes camera adjust to avatar moving (because of input, or because of gravity or other external code) and to not being blocked by the collider.
|
|
property AimAvatar: TAimAvatar read FAimAvatar write FAimAvatar default aaNone; |
If not aaNone then rotating the camera also rotates (with some delay) the avatar, to face the same direction as the camera. This allows to rotate the avatar with mouse look (which is comfortable), on the other hand it takes away some flexibility, e.g. you cannot look at avatar's face for a long time anymore.
|
|
property ImmediatelyFixBlockedCamera: Boolean read FImmediatelyFixBlockedCamera write FImmediatelyFixBlockedCamera
default false; |
Immediately (not with delay of CameraSpeed) update camera to never block avatar view by a wall, enemy etc. When it is True , we avoid seeing an invalid geometry (e.g. from the wrong side of the wall or inside a creature) ever, but in exchange the camera sometimes has to be adjusted very abrtupty (testcase: third_person_navigation demo, stand in the middle of moving enemies, and look around).
|
|
property MoveSpeed: Single read FMoveSpeed write FMoveSpeed
default DefaultMoveSpeed; |
Speed of movement by keys.
|
|
property CrouchSpeed: Single read FCrouchSpeed write FCrouchSpeed
default DefaultCrouchSpeed; |
Speed of movement by keys, when crouching.
|
|
property RunSpeed: Single read FRunSpeed write FRunSpeed
default DefaultRunSpeed; |
Speed of movement by keys, when running.
|
|
property RotationSpeed: Single read FRotationSpeed write FRotationSpeed
default DefaultRotationSpeed; |
Speed of rotating by keys, in radians per second.
|
|
property AnimationIdle: String read FAnimationIdle write FAnimationIdle stored AnimationIdleStored nodefault; |
Animation when character is not moving, not rotating and not crouching. Default 'idle'.
|
|
property AnimationRotate: String read FAnimationRotate write FAnimationRotate stored AnimationRotateStored nodefault; |
Animation when character is rotating, but otherwise remains in place (not moving) and it is not crouching. Default 'rotate'.
|
|
property AnimationWalk: String read FAnimationWalk write FAnimationWalk stored AnimationWalkStored nodefault; |
Animation when character is walking. Default 'walk'.
|
|
property AnimationRun: String read FAnimationRun write FAnimationRun stored AnimationRunStored nodefault; |
Animation when character is running. Default 'run'.
|
|
property AnimationCrouch: String read FAnimationCrouch write FAnimationCrouch stored AnimationCrouchStored nodefault; |
Animation when character is moving while crouching. Default 'crouch'.
|
|
property AnimationCrouchIdle: String read FAnimationCrouchIdle write FAnimationCrouchIdle stored AnimationCrouchIdleStored nodefault; |
Animation when character is crouching (Input_Crouch is pressed) but not moving or rotating. Default 'crouch_idle'.
|
|
property AnimationCrouchRotate: String read FAnimationCrouchRotate write FAnimationCrouchRotate stored AnimationCrouchRotateStored nodefault; |
Animation when character is crouching (Input_Crouch is pressed) and rotating, but not moving. Default 'crouch_rotate'.
|
|
property Radius; |
Camera will keep at least this distance from walls.
|
|
property AvatarTargetPersistent: TCastleVector3Persistent read FAvatarTargetPersistent ; |
AvatarTarget that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write AvatarTarget directly.
See also
- AvatarTarget
- Translation, from the avatar origin, to the "target" of the avatar where camera looks at.
|
Generated by PasDoc 0.16.0.