HUD Cursor / Reticle

The HUD cursor/reticle is a UI object that is controlled by the mouse, and helps with weapon aiming, target selection, steering and more.

The HUD cursor is not the same as the normal mouse cursor. They are separate because it is not possible to have full control of the mouse cursor (for example setting its position is impossible).

Setting Up

To set up the HUD cursor:

  1. Add a HUD Cursor component to your vehicle

  2. Customize the inspector settings

You will need to create a canvas and create the cursor UI object to fill out these settings.

Viewport Position

The viewport position is the position on a screen with a width and height of 1 (so for example, the viewport position of the center of the screen is (0.5, 0.5).

You can get or set the viewport position of the HUD cursor as follows:

// Get the viewport position
Vector3 viewportPos = myHUDCursor.ViewportPosition;

// Set the viewport position
myHUDCursor.SetViewportPosition(somePosition);

Aim Direction

You may want to know what direction in the scene the cursor is aiming, for example to know if it is pointing at an object.

You can get this with the following code:

// Get the world space aim direction
Vector3 aimDirection = myHUDCursor.AimDirection;

Center The Cursor

To set the HUD Cursor at the center of the screen, use the following code:

// Center the HUD cursor
myHUDCursor.CenterCursor();

Last updated