怪兽卡车
如何使用载具系统创建怪兽卡车。

Server/Index.lua
-- Spawns a Pickup
local vehicle = VehicleWheeled(
Vector(0, 0, 100), -- location
Rotator(), -- rotation
"nanos-world::SK_Pickup", -- asset
CollisionType.Normal, -- collision_type
true, -- gravity_enabled
false, -- auto_unflip
"nanos-world::A_Vehicle_Engine_10", -- engine_sound
"nanos-world::A_Vehicle_Horn_Toyota", -- horn_sound
"nanos-world::A_Vehicle_Brake", -- brake_sound
"nanos-world::A_Car_Engine_Start", -- engine_start_sound
"nanos-world::A_Vehicle_Door", -- vehicle_door_sound
true, -- auto_start_engine
"", -- custom_animation_blueprint
SpawnMode.AfterConstructor -- spawn_mode: waits for FinishSpawn() before sending it to clients
)
-- Configures the engine max torque, the steering wheel position and the headlights position
vehicle:SetEngineSetup(4500)
vehicle:SetSteeringWheelSetup(Vector(0, 27, 120), 24)
vehicle:SetHeadlightsSetup(Vector(250, 0, 70))
-- Adds 4 Static Mesh wheels attached to each mesh's Wheel Bone (those won't have collision and are visual only)
vehicle:AddStaticMeshAttached("wheel_rear_left", "nanos-world::SM_Tire_01", "Wheel_Rear_Left", Vector(0, -35, 0), Rotator(0, -90, 0))
vehicle:AddStaticMeshAttached("wheel_rear_right", "nanos-world::SM_Tire_01", "Wheel_Rear_Right", Vector(0, 45, 0), Rotator(0, -90, 0))
vehicle:AddStaticMeshAttached("wheel_front_left", "nanos-world::SM_Tire_01", "Wheel_Front_Left", Vector(0, -35, 0), Rotator(0, 90, 0))
vehicle:AddStaticMeshAttached("wheel_front_right", "nanos-world::SM_Tire_01", "Wheel_Front_Right", Vector(0, 45, 0), Rotator(0, 90, 0))
-- Configures each "Physical" Wheel, note that as our Wheel Static Mesh has height of 160 and width 60, we configure the wheels to have radius
-- of 80 and width 60, also because of SK_Pickup bones are not perfectly aligned, left wheels must be laterally offset a bit
vehicle:SetWheel(0, "Wheel_Front_Left", 80, 60, 30, Vector(0, -80, 0))
vehicle:SetWheel(1, "Wheel_Front_Right", 80, 60, 30, Vector(0, 90, 0))
vehicle:SetWheel(2, "Wheel_Rear_Left", 80, 60, 0, Vector(0, -80, 0))
vehicle:SetWheel(3, "Wheel_Rear_Right", 80, 60, 0, Vector(0, 90, 0))
-- Adds only a Driver (seat 0) and a Passenger (seat 1) door/seat
-- Parameters: seat index, door trigger location, seat location, seat rotation, trigger radius, leave lateral offset
vehicle:SetDoor(0, Vector(50, -75, 105), Vector( 8, -32.5, 95), Rotator(0, 0, 10), 70, -150)
vehicle:SetDoor(1, Vector(50, 75, 105), Vector(25, 50, 90), Rotator(0, 0, 0), 70, 150)
-- We deferred the spawn, so finish it now: clients build the vehicle (and its physics) only once, after all configuration
vehicle:FinishSpawn()