# Character Enter/Exit



{% embed url="https://vimeo.com/484163363" %}
Video tutorial covering entering/exiting vehicles with a character.
{% endembed %}

During the game, you may have a character that you wish to enter or exit a vehicle with by physically approaching and interacting with the vehicle. The following sections show you how to do this.

To enter/exit a vehicle without physically interacting with it (in code) see [this section](game-agents).

### Setting Up The Character

To begin, set up your character as a vehicle. This might sound strange, but a character is simply another representation for what the player is controlling.

1. Add a **Vehicle** component
2. Add a **Rigidbody** component (may be kinematic or not)
3. Add a **Vehicle Enter Exit Manager** component
4. Make sure the character has a collider of some kind (may be a Character Controller)

### Setting Up The Vehicle

Next, set up the vehicle:

1. Make sure it has a **Vehicle** component
2. Make sure it has a **Rigidbody** component (kinematic or not)
3. Add a **Vehicle Enter Exit Manager** component
4. Add a trigger collider, positioned where the character must be to enter the vehicle, and drag it into the _Enter Exit Collider_ field in the inspector of the **Vehicle Enter Exit Manager** component.
5. Add a new game object somewhere in the vehicle's hierarchy to represent where the character should be spawned when exiting the vehicle, and drag it into the _Spawn Point_ variable in the inspector of the **Vehicle Enter Exit Manager** component.

{% hint style="info" %}
Note that for spaceships, you can use the **Ship Enter Exit Manager** component instead of the **Vehicle Enter Exit Manager** component, as it comes with functionality for preventing enter/exit when she ship is not landed.
{% endhint %}

### Setting Up The Game Agent

Add a **Player Input\_Input System\_Enter Exit Controls** component somewhere in the hierarchy of the Game Agent you want to be able to switch vehicles.

{% hint style="info" %}
To rebind the controls, go to the project tab and double click the General Input Asset to open up the Input System editor. By default, the control used for entering and exiting is the _General Controls > Use_ control.
{% endhint %}

### Enter/Exit Prompts

To set up a text prompt for entering/exiting:&#x20;

1. Set up a text component somewhere in the scene or as part of the character's HUD (can be UGUI or TMPro).
2. If you're using TMPro, add a **UVCText\_TMProUGUI** component to the text object OR if you're using UGUI, add a **UVCText\_UGUI** component to the text object.
3. Drag the text object into the 'Prompt Text' field of the **Vehicle Enter Exit Manager** components on both the character and the vehicle.

Now you should get a prompt when you can enter or exit a vehicle.

To customize the prompts:

1. Go to the **PlayerInput\_InputSystem\_EnterExitControls** component you set up earlier.
2. Customize the enter/exit prompts.

{% hint style="info" %}
To make sure that the prompts always refer to the control bindings you have set up, be sure to refer to the controls with _{control}_. Anywhere this appears in a prompt, it will be replaced at runtime with the correct control reference.
{% endhint %}

### Putting It Together

Now, to be able to enter a vehicle, the Game Agent must be controlling the character vehicle you just set up, so drag the character vehicle into the _Starting Vehicle_ field in the inspector of the Game Agent component.&#x20;

Now run the scene.

When the character enters the trigger collider you set up on the vehicle, you can enter the vehicle by pressing the relevant input (by default, the F key).

If you want the player to start off in the vehicle (not the character) but to be able to exit to the character, drag the character vehicle into the _Starting Child Vehicle_ field in the inspector of the **Vehicle Enter Exit Manager** component on the vehicle.

### Starting Inside Vehicle

If the player starts off in a vehicle other than the character, but you still want them to be able to exit to the character during gameplay, make sure to go to whatever vehicle the player starts off in, go to its **Vehicle Enter Exit Manager** component, and set _Starting Child Vehicle_ to the character.

### Camera Control

If you're using a third party character controller (or your own) you probably want to switch off the character's camera controller when the character enters the vehicle.

You can easily do this by going to the character's **Vehicle Enter Exit Manager** and using the 'On Entered Parent' event to call a function to disable your camera controller, and the 'On Exited Parent' event to enable it again.

If you don't want to use the camera system provided in the kit for following your character, be sure not to add a **Camera Target** to the character, and the vehicle camera will simply do nothing and become passive when the player switches to the character.



