Walking
Reference for `gameplay_walk`, which manages the walking mode (first-person on-foot via the "unicycle" vehicle). Handles toggling between walking and driving, entering/exiting vehicles, proximity dete
Reference for gameplay_walk, which manages the walking mode (first-person on-foot via the "unicycle" vehicle). Handles toggling between walking and driving, entering/exiting vehicles, proximity detection, and vehicle blacklisting.
Module Exports (M)
Walking State
| Function | Signature | Description |
|---|---|---|
isWalking | () → bool | Returns true if player is on the unicycle |
setWalkingMode | (enabled, pos?, rot?, force?) → success, unicycleId | Toggles walking mode on/off |
toggleWalkingMode | () | Toggle - enters walking or gets in nearby vehicle |
getPlayerUnicycle | () → veh|nil | Returns the unicycle vehicle if player is on it |
isAtParkingSpeed | () → bool | Returns true if current vehicle is slow enough to exit |
Vehicle Interaction
| Function | Signature | Description |
|---|---|---|
getVehicleInFront | () → veh|nil | Returns the nearest enterable vehicle while walking |
getInVehicle | (vehicle) | Enters a vehicle, deactivates unicycle |
getDoorsidePosRot | (veh) → pos, front, up | Calculates driver-door-side spawn position |
Position & Rotation
| Function | Signature | Description |
|---|---|---|
getPosRot | () → pos, quat | Returns walking position and camera quaternion |
getPosXYZ | () → x, y, z | Returns walking position components |
getRotXYZW | () → x, y, z, w | Returns camera quaternion components |
setRot | (front, up) | Sets unicycle camera direction |
Toggling Control
| Function | Signature | Description |
|---|---|---|
enableToggling | (enabled) | Enable/disable walking mode toggle |
isTogglingEnabled | () → bool | Check if toggling is allowed |
Vehicle Blacklist
| Function | Signature | Description |
|---|---|---|
addVehicleToBlacklist | (vehId) | Prevent entering this vehicle while walking |
removeVehicleFromBlacklist | (vehId) | Allow entering this vehicle again |
isVehicleBlacklisted | (vehId) → bool | Check if blacklisted |
clearBlacklist | () | Clear all blacklist entries |
getBlacklist | () → table | Returns the blacklist table |
Hooks / Lifecycle
| Function | Description |
|---|---|
onUpdate | Per-frame: checks vehicle proximity, shows enter message, manages unicycle alpha |
onSerialize | Saves toggling state and blacklist |
onDeserialize | Restores toggling state and blacklist |
onClientStartMission | Clears blacklist and re-enables toggling |
onVehicleSwitched | Updates active state, resets unicycle alpha on switch |
Internals
Speed Thresholds
| Threshold | Value | Description |
|---|---|---|
lowerStoppingSpeed | 5 km/h | Below this → at parking speed |
higherStoppingSpeed | 6 km/h | Above this → not at parking speed |
M.addVehicleToBlacklist | (vehId) | - |
M.clearBlacklist | () | - |
M.enableToggling | (enabled) | - |
M.getBlacklist | () | - |
M.getDoorsidePosRot | (veh) | - |
M.getInVehicle | (vehicle) | - |
M.getPlayerUnicycle | (veh) | - |
M.getPosRot | () | - |
M.getPosXYZ | () | - |
M.getRotXYZW | () | - |
M.getVehicleInFront | () | - |
M.isAtParkingSpeed | () | - |
M.isTogglingEnabled | () | - |
M.isVehicleBlacklisted | (vehId) | - |
M.isWalking | () | - |
M.onClientStartMission | (levelPath) | - |
M.onDeserialize | (data) | - |
M.onSerialize | () | - |
M.onUpdate | (dtReal, dtSim) | - |
M.onVehicleSwitched | (oldId, newId, player) | - |
M.removeVehicleFromBlacklist | (vehId) | - |
M.setRot | (front, up) | - |
M.setWalkingMode | (enabled, pos, rot, force) | - |
M.toggleWalkingMode | () | - |
Hysteresis between the two prevents flickering at the threshold.
Vehicle Proximity Detection
Each frame while walking, the system:
- Iterates all vehicles (excluding blacklisted, non-playerUsable, inactive, and unicycles)
- Computes bounding-box distance to the player using the vehicle's OOBB
- The closest vehicle within 2m becomes
vehicleInFront - If that vehicle is at parking speed, shows "enter vehicle" message
Bounding Box Distance
Uses the vehicle's oriented bounding box (OOBB) with 8 corner points. Calculates minimum distance from the player position to all 16 edge segments of the box - more accurate than center-to-center distance for large vehicles.
Unicycle Management
- The "unicycle" is a special JBeam vehicle used as the walking avatar
- When entering a vehicle: unicycle is deactivated (physics stopped, hidden)
- When exiting: unicycle is teleported to the driver's door side
- In career mode, uses
without_mesh.pcconfig (invisible unicycle) - Unicycle mesh alpha fades based on camera distance (invisible in first person)
Driver Door Positioning
getDoorsidePosRot() calculates exit position:
- Gets reference nodes (ref, left) for vehicle orientation
- Gets driver node position and handedness (LHD/RHD)
- Offsets to the door side by
initialNodePosBBextents + 0.7m body offset - Returns position looking toward the vehicle center
How It Works
- Player presses walk toggle →
setWalkingMode(true)firesonBeforeWalkingModeToggled - Unicycle spawned/teleported to driver door side via
getOutOfVehicle() - Player enters unicycle, unicycle camera activated
onUpdatechecks proximity to vehicles, shows enter message- Player presses toggle near a stopped vehicle →
setWalkingMode(false) - Unicycle deactivated, player enters the nearby vehicle
Usage Example
-- Check if player is walking
if gameplay_walk.isWalking() then
local x, y, z = gameplay_walk.getPosXYZ()
log("I", "", string.format("Walking at %0.1f, %0.1f, %0.1f", x, y, z))
end
-- Programmatically enter walking mode at a position
gameplay_walk.setWalkingMode(true, vec3(100, 200, 50))
-- Blacklist traffic vehicles from being enterable
gameplay_walk.addVehicleToBlacklist(trafficVehId)
-- Get the vehicle the player is looking at
local veh = gameplay_walk.getVehicleInFront()
if veh then
log("I", "", "Near vehicle: " .. veh:getJBeamFilename())
endSee Also
- Gameplay Achievement - Related reference
- Gameplay City - Related reference
- discover - Discover / Experience System - Related reference
- Gameplay Systems Guide - Guide
Vehicle Performance
Reference for `gameplay_vehiclePerformance`, which calculates a Performance Index (PI) from drag test data and assigns vehicles to performance classes (D through X).
G2G Activity
Background activity that spawns random vehicles into the world. Uses a step-based sequence with fade-to-black transitions for vehicle spawning.