Navigation handles user input (key presses, mouse movement, touches on mobile devices, …) to control the camera.
To use a navigation, just create and add the navigation component as a child of TCastleViewport. You can control the Exists property of the navigation to enable / disable it.
TCastleViewport
Exists
As TCastleNavigation class is abstract, you actually have to use some descendant of it, like:
TCastleNavigation
TCastleWalkNavigation - typical first-person 3D navigation.
TCastleWalkNavigation
Depending on the TCastleWalkNavigation.Gravity value, it feels more like walking (when Gravity is true) or flying (when Gravity is false).
TCastleWalkNavigation.Gravity
Gravity
true
false
You can configure many properties of this navigation, e.g. to change speed manipulate TCastleWalkNavigation.MoveSpeed, TCastleWalkNavigation.MoveHorizontalSpeed, TCastleWalkNavigation.MoveVerticalSpeed.
TCastleWalkNavigation.MoveSpeed
TCastleWalkNavigation.MoveHorizontalSpeed
TCastleWalkNavigation.MoveVerticalSpeed
TCastleSceneCore.PreciseCollisions
TCastleExamineNavigation - inspect the 3D model, moving and rotating it to easily look at every side.
TCastleExamineNavigation
TCastle2DNavigation - specialized navigation for 2D. Makes it easy to move a 2D world, without accidentally making a rotation that would reveal it is 3D.
TCastle2DNavigation
TCastleThirdPersonNavigation - 3rd-person navigation in which an avatar of the player is shown. This navigation requires an animater avatar to use, see examples/third_person_camera how to set it up.
TCastleThirdPersonNavigation
You have complete freedom how do you handle the input in your games. You can:
use one of our ready navigation classes listed above,
or implement a new descendant of TCastleNavigation,
or implement navigation simply by processing the keys and updating the camera position / rotation from anywhere you want.
For example, move the camera in response to user input in your TViewPlay.Update. Example code would be like this (see manual about handling view events):
TViewPlay.Update
procedure TViewPlay.Update(const SecondsPassed: Single; var HandleInput: Boolean); const MoveSpeed = 10; begin inherited; MyViewport.Camera.Translation := MyViewport.Camera.Translation + MyViewport.Camera.Direction * SecondsPassed * MoveSpeed; end;
See the Tutorial: Designing a 3D world and Tutorial: Designing a 2D world to see the typical workflow how do you manipulate the navigation using the editor.
To improve this documentation just edit this page and create a pull request to cge-www repository.