Class TCastleWalkNavigation
Unit
Declaration
type TCastleWalkNavigation = class(TCastleMouseLookNavigation)
Description
Navigation by walking or flying (classic first-person shooter navigation) in a 3D scene. User can rotate and move camera using various keys, like arrows or AWSD. Mouse dragging and mouse look are also supported.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TInputListener
- TCastleUserInterface
- TCastleNavigation
- TCastleMouseLookNavigation
- TCastleWalkNavigation
Overview
Fields
![]() |
nested const DefaultFallSpeedStart = 0.5; |
![]() |
nested const DefaultGrowSpeed = 1.0; |
![]() |
nested const DefaultJumpMaxHeight = 1.0; |
![]() |
nested const DefaultMinAngleFromGravityUp = Pi * 10 / 180; |
![]() |
nested const DefaultRotationHorizontalSpeed = Pi * 150 / 180; |
![]() |
nested const DefaultRotationVerticalSpeed = Pi * 100 / 180; |
![]() |
nested const DefaultFallSpeedIncrease = 13/12; |
![]() |
nested const DefaultJumpHorizontalSpeedMultiply = 2.0; |
![]() |
nested const DefaultJumpTime = 1.0 / 8.0; |
![]() |
nested const DefaultMouseDraggingHorizontalRotationSpeed = Pi * 0.1 / 180; |
![]() |
nested const DefaultMouseDraggingVerticalRotationSpeed = Pi * 0.1 / 180; |
![]() |
nested const DefaultMouseDraggingMoveSpeed = 0.01; |
Methods
![]() |
function ReallyEnableMouseDragging: boolean; override; |
![]() |
procedure ProcessMouseLookDelta(const Delta: TVector2); override; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
destructor Destroy; override; |
![]() |
function PropertySection(const PropertyName: String): TPropertySection; override; |
![]() |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
![]() |
function AllowSuspendForInput: boolean; override; |
![]() |
function Press(const Event: TInputPressRelease): boolean; override; |
![]() |
function SensorTranslation(const X, Y, Z, Length: Double; const SecondsPassed: Single): boolean; override; |
![]() |
function SensorRotation(const X, Y, Z, Angle: Double; const SecondsPassed: Single): boolean; override; |
![]() |
function DirectionInGravityPlane: TVector3; |
![]() |
procedure Init(const AInitialPosition, AInitialDirection, AInitialUp: TVector3; const AGravityUp: TVector3; const APreferredHeight: Single; const ARadius: Single); overload; deprecated 'use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually'; |
![]() |
procedure Init(const box: TBox3D; const ARadius: Single); overload; deprecated 'use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually'; |
![]() |
function Motion(const Event: TInputMotion): boolean; override; |
![]() |
procedure CancelFalling; |
![]() |
function MaxJumpDistance: Single; |
![]() |
function RealPreferredHeight: Single; |
![]() |
procedure FallOnTheGround; |
![]() |
function GetNavigationType: TNavigationType; override; |
![]() |
procedure UpPrefer(const AUp: TVector3); deprecated 'use Viewport.Camera.UpPrefer'; |
Properties
![]() |
property PreferGravityUpForRotations: boolean
read FPreferGravityUpForRotations write FPreferGravityUpForRotations default true; |
![]() |
property PreferGravityUpForMoving: boolean
read FPreferGravityUpForMoving write FPreferGravityUpForMoving default true; |
![]() |
property MinAngleFromGravityUp: Single
read FMinAngleFromGravityUp write FMinAngleFromGravityUp
default DefaultMinAngleFromGravityUp; |
![]() |
property FallSpeedStart: Single
read FFallSpeedStart write FFallSpeedStart
default DefaultFallSpeedStart; |
![]() |
property FallSpeedIncrease: Single
read FFallSpeedIncrease write FFallSpeedIncrease
default DefaultFallSpeedIncrease; |
![]() |
property Falling: boolean read FFalling write FFalling; |
![]() |
property FallingEffect: boolean
read FFallingEffect write FFallingEffect default true; |
![]() |
property GrowSpeed: Single
read FGrowSpeed write FGrowSpeed
default DefaultGrowSpeed; |
![]() |
property JumpMaxHeight: Single
read FJumpMaxHeight write FJumpMaxHeight default DefaultJumpMaxHeight; |
![]() |
property IsJumping: boolean read FIsJumping; |
![]() |
property JumpHorizontalSpeedMultiply: Single
read FJumpHorizontalSpeedMultiply write FJumpHorizontalSpeedMultiply
default DefaultJumpHorizontalSpeedMultiply; |
![]() |
property JumpTime: Single read FJumpTime write FJumpTime
default DefaultJumpTime; |
![]() |
property IsCrouching: boolean read FIsCrouching; |
![]() |
property FallingOnTheGround: boolean read FFallingOnTheGround; |
![]() |
property IsOnTheGround: boolean read FIsOnTheGround; |
![]() |
property IsWalkingOnTheGround: boolean read FIsWalkingOnTheGround; |
![]() |
property IsAbove: boolean read FIsAbove; |
![]() |
property AboveHeight: Single read FAboveHeight; |
![]() |
property AboveGround: PTriangle read FAboveGround write FAboveGround; |
![]() |
property Input_Forward: TInputShortcut read FInput_Forward; |
![]() |
property Input_Backward: TInputShortcut read FInput_Backward; |
![]() |
property Input_LeftRotate: TInputShortcut read FInput_LeftRotate; |
![]() |
property Input_RightRotate: TInputShortcut read FInput_RightRotate; |
![]() |
property Input_LeftRot: TInputShortcut read FInput_LeftRotate; deprecated 'use Input_LeftRotate'; |
![]() |
property Input_RightRot: TInputShortcut read FInput_RightRotate; deprecated 'use Input_RightRotate'; |
![]() |
property Input_LeftStrafe: TInputShortcut read FInput_LeftStrafe; |
![]() |
property Input_RightStrafe: TInputShortcut read FInput_RightStrafe; |
![]() |
property Input_UpRotate: TInputShortcut read FInput_UpRotate; |
![]() |
property Input_DownRotate: TInputShortcut read FInput_DownRotate; |
![]() |
property Input_IncreasePreferredHeight: TInputShortcut read FInput_IncreasePreferredHeight; |
![]() |
property Input_DecreasePreferredHeight: TInputShortcut read FInput_DecreasePreferredHeight; |
![]() |
property Input_GravityUp: TInputShortcut read FInput_GravityUp; |
![]() |
property Input_Run: TInputShortcut read FInput_Run; |
![]() |
property Input_MoveSpeedInc: TInputShortcut read FInput_MoveSpeedInc; |
![]() |
property Input_MoveSpeedDec: TInputShortcut read FInput_MoveSpeedDec; |
![]() |
property Input_Jump: TInputShortcut read FInput_Jump; |
![]() |
property Input_Crouch: TInputShortcut read FInput_Crouch; |
![]() |
property MoveForward: boolean read FMoveForward write FMoveForward; |
![]() |
property MoveBackward: boolean read FMoveBackward write FMoveBackward; |
![]() |
property AllowSlowerRotations: boolean
read FAllowSlowerRotations write FAllowSlowerRotations
default true; |
![]() |
property CheckModsDown: boolean
read FCheckModsDown write FCheckModsDown
default true; |
![]() |
property RotationHorizontalPivot: Single
read FRotationHorizontalPivot write FRotationHorizontalPivot default 0; |
![]() |
property MouseLook; |
![]() |
property MouseLookHorizontalSensitivity; |
![]() |
property MouseLookVerticalSensitivity; |
![]() |
property InvertVerticalMouseLook; |
![]() |
property RotationHorizontalSpeed: Single
read FRotationHorizontalSpeed write FRotationHorizontalSpeed
default DefaultRotationHorizontalSpeed; |
![]() |
property RotationVerticalSpeed: Single
read FRotationVerticalSpeed write FRotationVerticalSpeed
default DefaultRotationVerticalSpeed; |
![]() |
property MouseDraggingHorizontalRotationSpeed: Single
read FMouseDraggingHorizontalRotationSpeed write FMouseDraggingHorizontalRotationSpeed
default DefaultMouseDraggingHorizontalRotationSpeed; |
![]() |
property MouseDraggingVerticalRotationSpeed: Single
read FMouseDraggingVerticalRotationSpeed write FMouseDraggingVerticalRotationSpeed
default DefaultMouseDraggingVerticalRotationSpeed; |
![]() |
property MouseDraggingMoveSpeed: Single
read FMouseDraggingMoveSpeed write FMouseDraggingMoveSpeed
default DefaultMouseDraggingMoveSpeed; |
![]() |
property MouseDragMode: TMouseDragMode
read FMouseDragMode write FMouseDragMode default mdWalk; |
![]() |
property Gravity: boolean
read FGravity write FGravity default true; |
![]() |
property PreferredHeight; |
![]() |
property MoveHorizontalSpeed; |
![]() |
property MoveVerticalSpeed; |
![]() |
property MoveSpeed; |
Description
Fields
![]() |
nested const DefaultFallSpeedStart = 0.5; |
![]() |
nested const DefaultGrowSpeed = 1.0; |
![]() |
nested const DefaultJumpMaxHeight = 1.0; |
![]() |
nested const DefaultMinAngleFromGravityUp = Pi * 10 / 180; |
![]() |
nested const DefaultRotationHorizontalSpeed = Pi * 150 / 180; |
![]() |
nested const DefaultRotationVerticalSpeed = Pi * 100 / 180; |
![]() |
nested const DefaultFallSpeedIncrease = 13/12; |
![]() |
nested const DefaultJumpHorizontalSpeedMultiply = 2.0; |
![]() |
nested const DefaultJumpTime = 1.0 / 8.0; |
![]() |
nested const DefaultMouseDraggingHorizontalRotationSpeed = Pi * 0.1 / 180; |
![]() |
nested const DefaultMouseDraggingVerticalRotationSpeed = Pi * 0.1 / 180; |
![]() |
nested const DefaultMouseDraggingMoveSpeed = 0.01; |
Methods
![]() |
function ReallyEnableMouseDragging: boolean; override; |
![]() |
procedure ProcessMouseLookDelta(const Delta: TVector2); override; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
destructor Destroy; override; |
![]() |
function PropertySection(const PropertyName: String): TPropertySection; override; |
![]() |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
![]() |
function AllowSuspendForInput: boolean; override; |
![]() |
function Press(const Event: TInputPressRelease): boolean; override; |
![]() |
function SensorTranslation(const X, Y, Z, Length: Double; const SecondsPassed: Single): boolean; override; |
![]() |
function SensorRotation(const X, Y, Z, Angle: Double; const SecondsPassed: Single): boolean; override; |
![]() |
function DirectionInGravityPlane: TVector3; |
|
Return Direction vector rotated such that it is orthogonal to GravityUp. This way it returns Direction projected on the gravity horizontal plane, which neutralizes such things like raising / bowing your head. Result is always normalized (length 1). Note that when Direction and GravityUp are parallel, this just returns current Direction — because in such case we can't project Direction on the horizontal plane. | |
![]() |
procedure Init(const AInitialPosition, AInitialDirection, AInitialUp: TVector3; const AGravityUp: TVector3; const APreferredHeight: Single; const ARadius: Single); overload; deprecated 'use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually'; |
|
Warning: this symbol is deprecated: use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually Set the most important properties of this navigation, in one call. Sets initial camera properties (InitialPosition, InitialDirection, InitialUp), sets current camera properties to them (Position := InitialPosition and so on). Given here AInitialDirection, AInitialUp, AGravityUp will be normalized, and AInitialUp will be adjusted to be orthogonal to AInitialDirection (see SetInitialView). Sets also PreferredHeight and Radius. PreferredHeight may be adjusted to be sensible (by calling CorrectPreferredHeight(ARadius)). You can pass ARadius = 0.0 if you really don't want this PreferredHeight adjustment. | |
![]() |
procedure Init(const box: TBox3D; const ARadius: Single); overload; deprecated 'use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually'; |
|
Warning: this symbol is deprecated: use Viewport.Camera.Init, and set PreferredHeight, Radius and call CorrectPreferredHeight manually Alternative Init that sets camera properties such that an object inside Box is more or less "visible good". Sets InitialCameraXxx properties to make it look right, sets current CameraXxx properties to InitialCameraXxx. Sets GravityUp to the same thing as InitialUp. Sets also PreferredHeight to make it behave "sensibly". | |
![]() |
function Motion(const Event: TInputMotion): boolean; override; |
![]() |
procedure CancelFalling; |
|
If Falling, then this will force Falling to false without calling OnFallenDown. It's much like forcing the opinion that "camera is not falling down right now". Note that if we will find out (e.g. in nearest Update) that camera is still too high above the ground, then we will start falling down again, setting Falling back to true. (but then we will start falling down from the beginning with initial falling down speed). This is useful to call if you just changed Position because e.g. the player teleported somewhere (or e.g. game levels changed). In this case you just want to forget the fact that camera was falling down — no consequences (like lowering player's health, fadeout etc.). | |
![]() |
function MaxJumpDistance: Single; |
|
Returns just JumpMaxHeight * PreferredHeight, see JumpMaxHeight for explanation. | |
![]() |
function RealPreferredHeight: Single; |
|
The PreferredHeight slightly modified by head bobbing and crouch. It can be useful for collision detection between camera and something. | |
![]() |
procedure FallOnTheGround; |
|
This makes a visual effect of camera falling down horizontally on the ground. Nice to use when player died, and you want to show that it's body falled on the ground. This works by gradually changing Up such that it gets orthogonal to GravityUp. | |
![]() |
function GetNavigationType: TNavigationType; override; |
![]() |
procedure UpPrefer(const AUp: TVector3); deprecated 'use Viewport.Camera.UpPrefer'; |
|
Warning: this symbol is deprecated: use Viewport.Camera.UpPrefer Change up vector, keeping the direction unchanged. If necessary, the up vector provided here will be fixed to be orthogonal to direction. See TCastleTransform.UpPrefer for detailed documentation what this does. | |
Properties
![]() |
property PreferGravityUpForRotations: boolean
read FPreferGravityUpForRotations write FPreferGravityUpForRotations default true; |
|
If With Note that you can change it freely at runtime, and when you set With PreferGravityUpForMoving, this affects moving: horizontal moving (forward, backward, strafe), and vertical moving (Input_Jump and Input_Crouch when Gravity is
| |
![]() |
property PreferGravityUpForMoving: boolean
read FPreferGravityUpForMoving write FPreferGravityUpForMoving default true; |
![]() |
property MinAngleFromGravityUp: Single
read FMinAngleFromGravityUp write FMinAngleFromGravityUp
default DefaultMinAngleFromGravityUp; |
|
This sets the minimal angle (in radians) between GravityUp and Direction, and also between -GravityUp and Direction. This way vertical rotations (like Input_UpRotate, Input_DownRotate) are "bounded" to not allow player to do something strange, i.e. bow your head too much and raise your head too much. This is used only when PreferGravityUpForRotations is This must be always between 0 and Pi/2. Value of Pi/2 will effectively disallow vertical rotations (although you should rather do this in a "cleaner way" by calling MakeClear on Input_UpRotate and Input_DownRotate). | |
![]() |
property FallSpeedStart: Single
read FFallSpeedStart write FFallSpeedStart
default DefaultFallSpeedStart; |
|
Initial speed of falling down. Of course this is used only when Gravity is true. Note that while falling down, the camera will actually fall with greater and greated speed (this adds more realism to the gravity effect...). Note that this is always relative to Direction length. Direction determines moving speed — and so it determines also falling speed. The default DefaultFallSpeedStart is chosen to be something sensible, to usually get nice effect of falling. You can change it at any time, but note that if you change this while Falling is | |
![]() |
property FallSpeedIncrease: Single
read FFallSpeedIncrease write FFallSpeedIncrease
default DefaultFallSpeedIncrease; |
|
When falling down, the speed increases. Set this to 1.0 to fall down with constant speed (taken from FallSpeedStart). | |
![]() |
property Falling: boolean read FFalling write FFalling; |
|
Are we currently falling down because of gravity. | |
![]() |
property FallingEffect: boolean
read FFallingEffect write FFallingEffect default true; |
|
Make a nice dizzying camera effect when falling down. This adds temporary camera rotations simulating that you rotate randomly and helplessly when falling down. Of course this is meaningfull only when Gravity works. Note that changing it from | |
![]() |
property GrowSpeed: Single
read FGrowSpeed write FGrowSpeed
default DefaultGrowSpeed; |
|
When Gravity works and camera height above the ground is less than PreferredHeight, then we try to "grow", i.e. camera position increases along the GravityUp so that camera height above the ground is closer to PreferredHeight. This property (together with length of Direction, that always determines every moving speed) determines the speed of this growth. | |
![]() |
property JumpMaxHeight: Single
read FJumpMaxHeight write FJumpMaxHeight default DefaultJumpMaxHeight; |
|
How high can you jump ? The max jump distance is calculated as | |
![]() |
property IsJumping: boolean read FIsJumping; |
|
We are in the middle of a "jump" move right now. | |
![]() |
property JumpHorizontalSpeedMultiply: Single
read FJumpHorizontalSpeedMultiply write FJumpHorizontalSpeedMultiply
default DefaultJumpHorizontalSpeedMultiply; |
|
Scales the speed of horizontal moving during jump. | |
![]() |
property JumpTime: Single read FJumpTime write FJumpTime
default DefaultJumpTime; |
|
How fast do you jump up. This is the time, in seconds, in takes to reach MaxJumpDistance height when jumping. | |
![]() |
property IsCrouching: boolean read FIsCrouching; |
|
Is player crouching right now. | |
![]() |
property FallingOnTheGround: boolean read FFallingOnTheGround; |
|
| |
![]() |
property IsOnTheGround: boolean read FIsOnTheGround; |
|
This is You can use this e.g. to make some effects when player is on some special ground (standing or walking), e.g. hurt player when he's standing on some toxical ground. See also
| |
![]() |
property IsWalkingOnTheGround: boolean read FIsWalkingOnTheGround; |
|
This is The intention is that you can use this to make some "footsteps" sound for the player. | |
![]() |
property IsAbove: boolean read FIsAbove; |
|
Last known information about whether camera is over the ground. Updated by using Height call. For normal TCastleNavigation descendants, this means using OnInternalHeight callback, which is handled by TCastleViewport if you assigned TCastleViewport.Navigation to this navigation. These are updated continuously only when Gravity is We do not (and, currently, cannot) track here if AboveGround pointer will be eventually released (which may happen if you release your 3D scene, or rebuild scene causing octree rebuild). This is not a problem for navigation class, since we do not use this pointer for anything. But if you use this pointer, then you may want to take care to eventually set it to | |
![]() |
property AboveHeight: Single read FAboveHeight; |
![]() |
property AboveGround: PTriangle read FAboveGround write FAboveGround; |
![]() |
property Input_Forward: TInputShortcut read FInput_Forward; |
![]() |
property Input_Backward: TInputShortcut read FInput_Backward; |
![]() |
property Input_LeftRotate: TInputShortcut read FInput_LeftRotate; |
![]() |
property Input_RightRotate: TInputShortcut read FInput_RightRotate; |
![]() |
property Input_LeftRot: TInputShortcut read FInput_LeftRotate; deprecated 'use Input_LeftRotate'; |
|
Warning: this symbol is deprecated: use Input_LeftRotate | |
![]() |
property Input_RightRot: TInputShortcut read FInput_RightRotate; deprecated 'use Input_RightRotate'; |
|
Warning: this symbol is deprecated: use Input_RightRotate | |
![]() |
property Input_LeftStrafe: TInputShortcut read FInput_LeftStrafe; |
![]() |
property Input_RightStrafe: TInputShortcut read FInput_RightStrafe; |
![]() |
property Input_UpRotate: TInputShortcut read FInput_UpRotate; |
![]() |
property Input_DownRotate: TInputShortcut read FInput_DownRotate; |
![]() |
property Input_IncreasePreferredHeight: TInputShortcut read FInput_IncreasePreferredHeight; |
![]() |
property Input_DecreasePreferredHeight: TInputShortcut read FInput_DecreasePreferredHeight; |
![]() |
property Input_GravityUp: TInputShortcut read FInput_GravityUp; |
![]() |
property Input_Run: TInputShortcut read FInput_Run; |
![]() |
property Input_MoveSpeedInc: TInputShortcut read FInput_MoveSpeedInc; |
|
Change the MoveSpeed. | |
![]() |
property Input_MoveSpeedDec: TInputShortcut read FInput_MoveSpeedDec; |
![]() |
property Input_Jump: TInputShortcut read FInput_Jump; |
|
Jumping and crouching (when Gravity = | |
![]() |
property Input_Crouch: TInputShortcut read FInput_Crouch; |
![]() |
property MoveForward: boolean read FMoveForward write FMoveForward; |
|
Move forward, just like Input_Forward would be pressed. | |
![]() |
property MoveBackward: boolean read FMoveBackward write FMoveBackward; |
|
Move backward, just like Input_Backward would be pressed. | |
![]() |
property AllowSlowerRotations: boolean
read FAllowSlowerRotations write FAllowSlowerRotations
default true; |
|
If | |
![]() |
property CheckModsDown: boolean
read FCheckModsDown write FCheckModsDown
default true; |
|
Do we check what key modifiers are pressed and do something differently based on it?
If If | |
![]() |
property RotationHorizontalPivot: Single
read FRotationHorizontalPivot write FRotationHorizontalPivot default 0; |
|
Horizontal rotation can rotate around a vector that is | |
![]() |
property MouseLook; |
![]() |
property MouseLookHorizontalSensitivity; |
![]() |
property MouseLookVerticalSensitivity; |
![]() |
property InvertVerticalMouseLook; |
![]() |
property RotationHorizontalSpeed: Single
read FRotationHorizontalSpeed write FRotationHorizontalSpeed
default DefaultRotationHorizontalSpeed; |
|
Rotation keys speed, in radians per second. | |
![]() |
property RotationVerticalSpeed: Single
read FRotationVerticalSpeed write FRotationVerticalSpeed
default DefaultRotationVerticalSpeed; |
![]() |
property MouseDraggingHorizontalRotationSpeed: Single
read FMouseDraggingHorizontalRotationSpeed write FMouseDraggingHorizontalRotationSpeed
default DefaultMouseDraggingHorizontalRotationSpeed; |
|
Speed (radians per pixel delta) of rotations by mouse dragging. Relevant only if niMouseDragging in Input, and MouseDragMode is mdRotate or mdWalk. Separate for horizontal and vertical, this way you can e.g. limit (or disable) vertical rotations, useful for games where you mostly look horizontally and accidentally looking up/down is more confusing than useful. | |
![]() |
property MouseDraggingVerticalRotationSpeed: Single
read FMouseDraggingVerticalRotationSpeed write FMouseDraggingVerticalRotationSpeed
default DefaultMouseDraggingVerticalRotationSpeed; |
![]() |
property MouseDraggingMoveSpeed: Single
read FMouseDraggingMoveSpeed write FMouseDraggingMoveSpeed
default DefaultMouseDraggingMoveSpeed; |
|
Moving speed when mouse dragging. Relevant only when | |
![]() |
property MouseDragMode: TMouseDragMode
read FMouseDragMode write FMouseDragMode default mdWalk; |
|
What mouse dragging does. Used only when niMouseDragging in Input. | |
![]() |
property Gravity: boolean
read FGravity write FGravity default true; |
|
This unlocks a couple of features and automatic behaviors related to gravity. Gravity always drags the camera down to -GravityUp. Summary of things done by gravity:
While there are many properties allowing you to control gravity behavior, most of them have initial values that should be sensible in all cases. The most important property you need to set yourself is PreferredHeight. Everything else should basically work auto-magically. Note that Gravity setting is independent from PreferGravityUpForRotations or PreferGravityUpForMoving settings — PreferGravityUpXxx say how the player controls work, Gravity says what happens to player due to ... well, due to gravity. | |
![]() |
property PreferredHeight; |
![]() |
property MoveHorizontalSpeed; |
![]() |
property MoveVerticalSpeed; |
![]() |
property MoveSpeed; |
Generated by PasDoc 0.16.0.


