Log inGet started
World

Joyride Harbor: Drivable Cars, Boats and Aircraft Kit

README.md

Vehicle

A vehicle anyone can walk up to, get into, drive (or sail, or fly) and get out of. Put it on an entity (vehiclesKit.api.spawn does this for you, on a synced entity so every player shares the one vehicle) and set three fields: preset (kart, sportsCar, muscleCar, monsterTruck, buggy, deliveryTruck, bus, tank, hovercraft, speedboat, rowboat, arcadePlane, helicopter, spaceship), look (toy, lowPoly, realistic) and paint (auto or a paint name). It needs no sibling components: it adds its own Physics body, the engine's VehicleController (cars, tank) or a float for boats (the Tidewater water kit's Buoyancy when the world holds it, else the engine's FluidForces), and builds its model, colliders, wheels, seats and moving parts as local children on every peer. Changing preset rebuilds it as the other vehicle, with everything a brand-new one of that preset has (weight, gearbox, driving aids, floats, seats), parked or driven: the owner sets its physics up afresh, and the host takes a parked vehicle nobody owns long enough to do it. builtFor records the preset the physics was set up for. Whoever is aboard stays aboard through the change: riders keep their seats (one whose seat the new preset lacks moves to a free seat, and gets out only if none is left), and a seated rider's controls, HUD and camera switch to the new preset. The camera is framed afresh, exactly as getting in frames it: in the frame of the switch it lets go of its rig and holds still (moved out behind and above the new body if that spot is inside it), and a frame later it gets a fresh driveCams camera fitted to the new body.

  • Getting in: an interactKit prompt ("Drive", or "Ride" for a free passenger seat) on E, the gamepad's west button or the touch Interact button. The vehicle's owner decides who gets which seat (occupants), then hands ownership to the driver's peer, which simulates it while every other peer draws it from the poses it sends.
  • Seated: the rider's body is posed in the seat on every peer; the driver's camera switches to driveCams (chase, cockpit, bonnet; the camera button cycles), controls switch to the kit's controlsKit driving or flying scheme, and the HUD shows a gaugeClusters speedometer, a barsKit boost meter and button prompts. Getting out (E / west / touch Exit) restores the walking camera and controls and stands the player beside the door.
  • Boost drains boostCharge while held and refills after; drift is the handbrake for cars, a slide for the hovercraft and a hard carve for boats; horn plays on every peer.
  • It publishes torqueCars' driving contract (car.rpm, car.gear, car.kmh, player.vehicle, mount points...) so gaugeClusters, engineVoices and driveCams work with it unchanged; an engineVoices voice is attached while it is driven.
  • A vehicle nobody drives that has come to rest parks: its controller and per-step work sleep until someone gets in or it is pushed. On land that is under 0.3 m/s; a boat, which the swell never lets stand still, rests once its drift across the water (smoothed over about a second and a half) is under 1 m/s. Once every seat is empty and it is at rest, its owner releases it, so it belongs to nobody until the next player gets in (the host decides that seat, and the new driver's peer claims it). A boat or hovercraft is kept instead (the host claims one nobody owns), so it goes on floating.
  • Recover (R, View, touch Reset, or recover() on the owner) stands it upright, facing the same way, on level ground where it is or a body-length away; boats go back to deep water and aircraft over the sea back into the air.
  • Wheeled kinds keep their body collider at least 25 cm off the ground, so the wheels climb kerbs; no vehicle is ever moved faster than its top speed with boost (plus a margin) or spun faster than 6 rad/s.

Fields: preset, look, paint, passengers (allow riders), enterRange (metres beyond the vehicle's edge, 0 = 1.6), cameraModes (driveCams modes the camera button steps through); owner-written state: occupants, boostCharge, boosting, horn, builtFor. Methods: enter(seat?), exit(), driver(), seats(), info(), set({ preset, look, paint }), setIntent(t) (drive from code; any controls left out count as zero / off), recover(), rig(), isParked().