using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # PLAYER ENTERS -> FIRST PERSON + INPUT — Part 3 of "Scene Graph: Car Primitive". # # Getting "into" the car is the moment the experience changes. Two real, # fully-public mechanisms make it happen: # # 1. DETECT ENTRY with a Mutator Zone placed around the car. Its # `AgentEntersEvent : listenable(agent)` fires when a player walks in, and # `AgentExitsEvent` fires when they leave. (You can also use a vehicle # spawner's `AgentEntersVehicleEvent`, but a zone works for our prop "car".) # # 2. SWITCH THE VIEW with a Gameplay Camera device. The First-Person flavour, # `gameplay_camera_first_person_device`, has a public `AddTo(Agent)` that # pushes a first-person camera onto that player, and `RemoveFrom(Agent)` to # pop it. So: on enter -> AddTo, on exit -> RemoveFrom. # # About input: a creator CANNOT author custom input actions/mappings in Verse # (those constructors are Epic-internal). What you CAN do is react to input. The # cleanest public path is an Input Trigger device: configure its key in the # Details panel, then subscribe to `PressedEvent : listenable(agent)`. Here we # only honk while the player is in the car — proof the camera switch and the # input subscription are both live for the right player. # # This device uses @editable references (no tags) so you can see exactly which # zone, camera, and input trigger it drives. car_first_person_enter_device := class(creative_device): # Walk-in zone around the car. @editable EntryZone : mutator_zone_device = mutator_zone_device{} # The first-person camera pushed onto the driver. @editable DriverCamera : gameplay_camera_first_person_device = gameplay_camera_first_person_device{} # An Input Trigger device (configure its key in the Details panel) used as the # "horn" while seated. @editable HornInput : input_trigger_device = input_trigger_device{} OnBegin() : void = EntryZone.AgentEntersEvent.Subscribe(OnEnter) EntryZone.AgentExitsEvent.Subscribe(OnExit) HornInput.PressedEvent.Subscribe(OnHorn) Print("CarFirstPerson: zone, camera, and horn input wired.") # Player got in: push first person and register them for the horn input. OnEnter(Agent : agent) : void = DriverCamera.AddTo(Agent) HornInput.Register(Agent) Print("CarFirstPerson: driver entered -> first person ON.") # Player got out: pop the camera and stop tracking their input. OnExit(Agent : agent) : void = DriverCamera.RemoveFrom(Agent) HornInput.Unregister(Agent) Print("CarFirstPerson: driver exited -> first person OFF.") # The configured key was pressed by a seated driver. OnHorn(Agent : agent) : void = Print("CarFirstPerson: HONK!")