Integration: Enter-Exit Vehicle (BCG Shared Assets)

Table of Contents

BCG Shared Assets is a separate addon package that provides a character controller system, allowing a player character to walk around, approach RCCP vehicles, and enter or exit them at runtime. It includes first-person (FPS), third-person (TPS), and mobile character controllers, along with camera management, input handling, and UI for interaction prompts.

This integration is not part of the core RCCP package. You must import it separately from the included installer.


Overview

The enter-exit system is event-driven. When the player approaches a vehicle and presses the interaction key, the system disables the character controller, parents it to the vehicle, enables vehicle control, and switches cameras. When exiting, the reverse occurs: the character is re-enabled at the vehicle's get-out position, vehicle control is disabled, and the character camera is restored.

Key design points:


Prerequisites


Installing

  1. Open the RCCP Welcome Window: Tools > BoneCracker Games > Realistic Car Controller Pro > Welcome Window.
  2. Navigate to the Addons tab.
  3. Click Download and import BCG Shared Assets.
  4. Unity will import BCG_SharedAssets.unitypackage from Addons/Installers/.
  5. After import, the scripting symbol BCG_ENTEREXIT is added automatically by RCCP_AddonDefineManager.
  6. Wait for Unity to recompile.

The installer package is located at:


Assets/Realistic Car Controller Pro/Addons/Installers/BCG_SharedAssets.unitypackage

After import, the BCG Shared Assets folder appears at:


Assets/BoneCracker Games Shared Assets/

Scripting Symbol

SymbolSet WhenRemoved When
BCG_ENTEREXITAssets/BoneCracker Games Shared Assets/ folder existsFolder is deleted (auto-detected by RCCP_AddonDefineManager)

If auto-detection fails, you can manually remove the symbol from Edit > Project Settings > Player > Other Settings > Scripting Define Symbols.


Core Components

BCG_EnterExitManager

Role: Scene-level singleton that orchestrates the entire enter-exit lifecycle.

Add Component: BoneCracker Games > BCG Shared Assets Pro > BCG Enter Exit Manager

The manager:

PropertyTypeDescription
activePlayerBCG_EnterExitPlayerThe currently active character controller.
cachedMainCamerasListAll vehicle cameras tracked by the manager.
cachedPlayersListAll spawned character controllers.
cachedVehiclesListAll spawned vehicles with enter-exit support.
cachedCanvasBCG_EnterExitCharacterUICanvasReference to the UI canvas for mobile/touch interaction.

BCG_EnterExitVehicle

Role: Marks an RCCP vehicle as enterable/exitable and defines its exit point and camera.

Add Component: BoneCracker Games > BCG Shared Assets Pro > BCG Enter Exit Vehicle

PropertyTypeDescription
correspondingCameraGameObjectThe camera to activate when the player enters this vehicle. Auto-detected from RCCP_Camera in the scene if not assigned.
driverBCG_EnterExitPlayerThe player currently driving this vehicle. null if empty.
getOutPositionTransformThe world position where the character spawns when exiting. If none is found, a child named "Get Out Pos" is created automatically at local position (-1.5, 0, 0).

When this component is enabled, it sends SetCanControl(false) to the vehicle, preventing it from driving until a player enters.

Events:

EventSignatureFired When
OnBCGVehicleSpawned(BCG_EnterExitVehicle)Component is enabled.
OnBCGVehicleDestroyed(BCG_EnterExitVehicle)Component is disabled.

BCG_EnterExitPlayer

Role: Marks a character controller as capable of entering vehicles.

Add Component: BoneCracker Games > BCG Shared Assets Pro > BCG Enter Exit Player

PropertyTypeDescription
isTPSControllerboolSet to true if this character uses a TPS controller with its own camera.
rayHeightfloatHeight offset for the interaction raycast (TPS mode). Default: 1.
canControlboolWhether the character accepts input.
showGuiboolWhether the "Press Interaction [TAB] Key To Get In" prompt is visible.
targetVehicleBCG_EnterExitVehicleThe vehicle currently in front of the player (detected by raycast).
playerStartsAsInVehicleboolIf true, the player begins the scene already inside inVehicle.
inVehicleBCG_EnterExitVehicleThe vehicle the player is currently inside. null if on foot.
characterCameraCameraThe FPS camera (auto-detected from children) or the TPS camera reference.

Detection: The player casts a ray forward (from the camera for FPS, from transform.position + Vector3.up * rayHeight for TPS) with a range of 1.5 meters. If the ray hits a collider whose parent has a BCG_EnterExitVehicle component, targetVehicle is set and the interaction prompt appears.

Events:

EventSignatureFired When
OnBCGPlayerSpawned(BCG_EnterExitPlayer)Component is enabled.
OnBCGPlayerDestroyed(BCG_EnterExitPlayer)Component is destroyed.
OnBCGPlayerEnteredAVehicle(BCG_EnterExitPlayer, BCG_EnterExitVehicle)Player enters a vehicle.
OnBCGPlayerExitedFromAVehicle(BCG_EnterExitPlayer, BCG_EnterExitVehicle)Player exits a vehicle.

BCG_EnterExitSettings

Role: Global settings ScriptableObject loaded from Resources/BCG_EnterExitSettings.

SettingTypeDefaultDescription
keepEnginesAlivebooltrueIf true, the engine remains running after the player exits.
startStopEnginebooltrueIf true, the engine starts on enter and stops (or remains per keepEnginesAlive) on exit.
enterExitSpeedLimitfloat20Maximum vehicle speed (km/h) at which the player can exit.
mobileControllerboolfalseIf true, uses mobile joystick input instead of keyboard/mouse.
autoLockMouseCursorbooltrueIf true, the cursor is locked when on foot and unlocked when in a vehicle.

Setup Guide

Step 1: Import BCG Shared Assets

Follow the installation steps above.

Step 2: Add BCG_EnterExitVehicle to Each Vehicle

  1. Select your RCCP vehicle in the Hierarchy.
  2. Add Component: BCG Enter Exit Vehicle.
  3. A child object named "Get Out Pos" is created automatically. Reposition it to a suitable door-side location.
  4. The correspondingCamera field auto-fills with the scene's RCCP_Camera. You can override it with a different camera if needed.

Step 3: Add BCG_EnterExitPlayer to Your Character

  1. Select or create your player character (use one of the included prefabs, or your own).
  2. Add Component: BCG Enter Exit Player.
  3. If using a TPS controller, enable isTPSController and assign the characterCamera.
  4. If you want the player to start inside a vehicle, enable playerStartsAsInVehicle and assign the inVehicle reference.

Step 4: Ensure BCG_EnterExitManager Exists

The manager auto-creates itself as a singleton if none exists in the scene. However, for explicit control you can add a GameObject named _BCGEnterExitManager and attach the BCG_EnterExitManager component.

Step 5: Configure Input

The interaction input is handled by BCG_InputManager, which reads from Unity's Input System. The default interaction action is bound to the Tab key in the Character action map.

Step 6: Configure UI (Optional)

For mobile or on-screen interaction buttons, add the BCG_EnterExitCharacterUICanvas prefab to the scene. It automatically switches between "On Foot" and "In Vehicle" UI groups.


Character Controllers

BCG Shared Assets includes three character controller prefabs, all located in Assets/BoneCracker Games Shared Assets/Prefabs/Character/:

BCG_FPSCharacterController

A first-person character controller using Unity's CharacterController component and the new Input System.

PropertyDefaultDescription
moveSpeed5Movement speed in units/second.
gravity-9.81Gravity applied each frame.
lookSensitivity2Mouse look sensitivity multiplier.
maxLookAngle90Maximum up/down look angle in degrees.

Prefab: BCG_FPSCharacterController.prefab

BCG_TPSCharacterController

A third-person character controller that rotates the character with the mouse and moves relative to facing direction.

PropertyDefaultDescription
moveSpeed5Movement speed in units/second.
gravity-9.81Gravity applied each frame.
lookSensitivity2Mouse look sensitivity multiplier.
rotationSpeed180Horizontal rotation speed in degrees/second.

Prefab: BCG_TPSCharacterController.prefab

BCG_MobileCharacterController

A mobile touch controller that reads from two on-screen joysticks (movement and camera) and provides static move and mouse vectors for other components to consume.

Prefab: BCG_FPSTPS MobileController.prefab (in Prefabs/UI/)

To use mobile controls, set BCG_EnterExitSettings.Instance.mobileController = true.


Camera

BCG_TPSCameraController

A third-person orbit camera for the character. Located at Assets/BoneCracker Games Shared Assets/Prefabs/Character/BCG_TPSCamera.prefab.

PropertyDefaultDescription
target(auto-detected)The transform to orbit around. Auto-finds BCG_TPSCharacterController if not assigned.
offset(0, 5, -10)Camera offset from target in local space.
distance10Orbit distance from target.
rotationSpeed5Camera rotation speed.
minYAngle / maxYAngle-30 / 60Vertical angle clamp to prevent camera flipping.
smoothSpeed0.125Camera movement smoothing factor.

This camera is only active when the player is on foot. When the player enters a vehicle, the manager disables it and enables the vehicle's correspondingCamera (typically RCCP_Camera).


Input System

BCG_InputManager

A singleton (RCCP_Singleton) that reads from Unity's Input System using the Character action map.

Input Actions (Character Map):

ActionDefault BindingDescription
MovementWASD / Arrow KeysCharacter movement (Vector2).
AimMouse DeltaCamera look (Vector2).
InteractTabEnter or exit the nearest vehicle.
CursorLockRight Mouse ButtonLock the cursor.
CursorUnlockEscapeUnlock the cursor.

Events:

EventFired When
OnInteractThe Interact action is performed.
OnCursorLockThe CursorLock action is performed.
OnCursorUnlockThe CursorUnlock action is performed.

The manager persists across scene loads via DontDestroyOnLoad. It automatically disables inputs on application pause/focus loss and re-enables them on resume.


UI Components

BCG_EnterExitCharacterUICanvas

Manages two UI groups that switch based on whether the player is on foot or in a vehicle.

PropertyTypeDescription
displayTypeDisplayTypeCurrent mode: OnFoot or InVehicle. Managed by BCG_EnterExitManager.
UisInVehicleGameObjectUI group shown when inside a vehicle.
UisOnFootGameObjectUI group shown when on foot.

This canvas only activates itself if BCG_EnterExitSettings.Instance.mobileController is true. On desktop, the built-in OnGUI text prompt on BCG_EnterExitPlayer is used instead.

BCG_UIInteractionButton

A simple button component that calls BCG_EnterExitManager.Instance.Interact() when tapped. Attach it to any UI Button for mobile enter/exit interaction.


Common Issues

Character does not enter the vehicle

Camera does not switch when entering/exiting

Vehicle drives on its own after player exits

Player appears inside the vehicle mesh on exit

Enter/exit happens twice rapidly


Lifecycle Diagram


Player on Foot                          Player in Vehicle
     |                                       |
     |-- Raycast hits vehicle               |
     |   targetVehicle = vehicle             |
     |   showGui = true                      |
     |                                       |
     |-- Press Interact (Tab)               |
     |   GetIn(targetVehicle)                |
     |   OnBCGPlayerEnteredAVehicle fires    |
     |                                       |
     |   Manager:                            |
     |     player.inVehicle = vehicle        |
     |     player.gameObject.SetActive(false)|
     |     Vehicle camera ON                 |
     |     SetCanControl(true)               |
     |     SetEngine(true)                   |
     |     RCCP_SceneManager.activeVehicle   |
     |                                       |
     |                             Press Interact (Tab)
     |                             GetOut()
     |                             OnBCGPlayerExitedFromAVehicle fires
     |                                       |
     |                             Manager:  |
     |                               player at getOutPosition
     |                               player.gameObject.SetActive(true)
     |                               All vehicle cameras OFF
     |                               SetCanControl(false)
     |                               SetEngine(keepEnginesAlive)
     |                               RCCP_SceneManager.activeVehicle = null

See Also


Support: bonecrackergames@gmail.com | www.bonecrackergames.com

Need help? See Troubleshooting