Portes
How to create a simple and automatic door when Characters move in.
Résultat final
Extrait de code
Server/Index.lua
-- Faisons apparaître un SM_Plane que nous utiliserons comme porte, et également un StaticMesh vide (SM_None) correspondant à notre charnière.
-- Le point de pivot du SM_Plane se trouvant au milieu du mesh, nous avons besoin d'une charnière pour permettre la bonne rotation.
-- Ceci n'est pas nécessaire si le Mesh de votre porte à déjà son point de pivot à l'emplacement de la charnière.
-- Spawns the Hinge (which we rotated 90º to stand up)
local door = StaticMesh(Vector(0, 0, 100), Rotator(0, 0, 90), "nanos-world::SM_None")
-- Spawns the Door mesh, scales it to be in the format of a door, and attaches it to the Hinge
local door_mesh = StaticMesh(Vector(), Rotator(), "nanos-world::SM_Plane")
door_mesh:SetScale(Vector(1, 2, 1))
-- Attaches to the Hinge at a relative location of 50 units (to be at the hinge location)
door_mesh:AttachTo(door)
door_mesh:SetRelativeLocation(Vector(50, 0, 0))
-- Spawns our trigger at the center of the Door
local trigger = Trigger(Vector(0, 0, 100), Rotator(), 150)
-- Registers the trigger when a Character moves in
trigger:Subscribe("BeginOverlap", function(trigger, actor)
if (actor:GetClass() ~= Character) then return end
-- Plays an opening door animation on the Character
actor:PlayAnimation("nanos-world::AM_Mannequin_DoorOpen_01", AnimationSlotType.UpperBody)
-- Rotates the door -90º smoothly
door:RotateTo(Rotator(0, -90, 90), 1)
end)
-- Registers the trigger when a Character moves out
trigger:Subscribe("EndOverlap", function(trigger, actor)
if (actor:GetClass() ~= Character) then return end
-- Rotates the door back to original position, smoothly
door:RotateTo(Rotator(0, 0, 90), 1)
end)