武器瞄准镜
这段示例代码展示了如何将自定义瞄准镜网格体附加到武器上,并使其作为真正的瞄准镜工作。

This snippet uses the AK47 weapon from the default-weapons Package, add it to the packages_requirements of your Package.toml first.
Server/Index.lua
-- Spawning the AK47 (default-weapons classes are available both as globals and in the NanosWorldWeapons table)
local my_ak47 = AK47(Vector(200, 0, 100), Rotator())
-- Adds a StaticMesh Attached with a RedDot mesh into AK47 on sight_socket bone from AK47 model. As our AK47 model already
-- have a bone named sight_socket at the right location, we can just attach to it, otherwise we would
-- need to set its Attach Location to where the RedDot fits and using bone name as empty ""
my_ak47:AddStaticMeshAttached("sight", "nanos-world::SM_T4_Sight", "sight_socket")
-- Makes the FOV multiplier reduces by 0.35x when ADS (aiming)
my_ak47:SetSightFOVMultiplier(0.35)
-- Sets the ADS transform offset to fit the RedDot center position,
-- each weapon will need a different offset to fit it's sight. AK47 + RedDot best fit is Z = -15.9
my_ak47:SetSightTransform(Vector(0, 0, -15.9), Rotator(0, 0, 0))
一些可用作瞄准镜的静态网格体资产:
nanos-world::SM_T4_Sight(red dot)nanos-world::SM_Scope_25x56(long range scope)
Other weapon attachments you can add the same way (they are visual only):
nanos-world::SM_Vertgripnanos-world::SM_Suppressor