Navigation

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.

As TCastleNavigation class is abstract, you actually have to use some descendant of it, like:

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):

    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.