Passer au contenu principal
Version: latest - a1.156.0 ⚖️

Viseur d'arme

Cet exemple de code montre comment attacher un mesh de viseur custom sur une arme et le rendre fonctionnel.

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))

Quelques Static Mesh pouvant être utilisés comme viseur :​

  • 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_Vertgrip
  • nanos-world::SM_Suppressor