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

Viseur d'arme

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

Cet exemple utilise l'arme AK47 du Package default-weapons : ajoutez-le d'abord aux packages_requirements de votre Package.toml.

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 (point rouge)
  • nanos-world::SM_Scope_25x56 (lunette longue portée)

D'autres accessoires d'arme peuvent être ajoutés de la même façon (ils sont purement visuels) :

  • nanos-world::SM_Vertgrip
  • nanos-world::SM_Suppressor