跳至正文
版本:最新版 - a1.156.0 ⚖️

扮演道具

如何使用角色模拟道具附身。这可用于道具躲猫猫游戏模式!

最终结果​

代码片段​

Server/Index.lua
-- Gives a "Prop" Character to each Player that joins
Player.Subscribe("Spawn", function(player)
SpawnPropCharacter(player)
end)

function SpawnPropCharacter(player)
-- Spawns a Character using SK_None mesh (an invisible mesh)
local new_char = Character(Vector(0, 0, 100), Rotator(), "nanos-world::SK_None")

-- Adjusts the Capsule of this character. For small props it's recommended to use small capsule size
-- (A capsule is used to handle Character's collision, this will also adjust camera height location)
-- It's important to adjust the Capsule Size before adding a StaticMesh, as it will be adjusted based on Capsule Size
new_char:SetCapsuleSize(32, 64)

-- Attaches a Static Mesh on the character - which will be the Prop it will possess
new_char:AddStaticMeshAttached("prop", "nanos-world::SM_WoodenChair")

-- Disables some functionalities from the Character (picking up stuff, ability to crouch, FPS camera...)
new_char:SetCanPickupPickables(false)
new_char:SetCanGrabProps(false)
new_char:SetCanCrouch(false)
new_char:SetCameraMode(CameraMode.TPSOnly) -- Allows only Third Person

-- Makes the Player control it
player:Possess(new_char)
end