Constraints — «связи» между деталями. Создаются через Model → Create (Constraints), соединяют две Attachment.
Вращение: низкая «SpinBase» (Anchored вкл.) и длинная палка «SpinBar» над ней (Anchored выкл.). Model → Create → Hinge: кликни сначала по верху основания, потом по низу палки.
У Attachment ось вращения — жёлтая стрелка. Поверни обе Attachment так, чтобы стрелки смотрели вверх (Orientation 0, 0, 90).
HingeConstraint: ActuatorType = Motor, AngularVelocity = 1.5 (скорость), MotorMaxTorque = 100000000 — иначе игрок остановит палку. В методичке был CylindricalConstraint — Hinge то же самое, только проще.
Пружина: «SpringBase» (Anchored вкл.) и площадка «Pad» над ней (Anchored выкл.). Model → Create → Spring между ними: Stiffness 2000, FreeLength — расстояние между ними, Damping 50.
Чтобы площадку не уносило вбок — добавь между теми же деталями Prismatic (направляющая). Обе Attachment стрелкой вверх.
Маятник: «PendulumTop» высоко (Anchored вкл.), шар «Ball» сбоку (Anchored выкл., Shape Ball). Model → Create → Rope между ними, Length — чуть больше расстояния. Шар отпущенный сбоку сам начнёт качаться.
Сделай шар тяжёлым: CustomPhysicalProperties вкл., Density 10 — он будет сбивать игроков.
Маятник и пружина со временем останавливаются или сбиваются игроками — «ResetScript» раз в 30 секунд ставит деталь на место без скорости, и всё начинается заново.
Скрипты
ResetScript
Где: Workspace → Pendulum → Ball (и Trampoline → Pad) · Script Зачем: Возвращает деталь на место.
-- маятник или площадка пружины
local part = script.Parent
-- раз в сколько секунд возвращаем на место
local RESET_TIME = 30
-- место и поворот в начале игры
local start = part.CFrame
-- бесконечно
while true do
-- ждём
task.wait(RESET_TIME)
-- гасим скорость
part.AssemblyLinearVelocity = Vector3.zero
-- гасим вращение
part.AssemblyAngularVelocity = Vector3.zero
-- ставим на старое место — маятник снова раскачивается
part.CFrame = start
-- конец цикла
end
Проверка
Запусти Play (или Run) и убедись:
Палка вращается; игрок, которого она задела, слетает с платформы.
Встань на площадку пружины — она проседает и подкидывает обратно.
Шар качается поперёк дорожки; через 30 секунд снова стартует с исходной точки.
Roblox · Obby · lesson 4
Mechanisms: spinner, spring, pendulum
Moving obstacles without complex scripts — built with Constraints: a spinning bar, a spring pad and a pendulum on a rope.
Structure
Blue — what we add in this lesson.
Workspace
├─ Spinner (Model)
│ ├─ SpinBase (Part)— Anchored on
│ │ ├─ A0 (Attachment)
│ │ └─ Motor (HingeConstraint)— ActuatorType Motor
│ └─ SpinBar (Part)— Anchored off
│ └─ A1 (Attachment)
├─ Trampoline (Model)
│ ├─ SpringBase (Part)— Anchored on
│ │ ├─ Spring (SpringConstraint)
│ │ └─ Slider (PrismaticConstraint)
│ └─ Pad (Part)— Anchored off
│ └─ ResetScript (Script)
└─ Pendulum (Model)
├─ PendulumTop (Part)— Anchored on
│ └─ Rope (RopeConstraint)
└─ Ball (Part)— Anchored off
└─ ResetScript (Script)
Steps
Constraints are "links" between parts. They are created through Model → Create (Constraints) and connect two Attachments.
Spinner: a low "SpinBase" (Anchored on) and a long bar "SpinBar" above it (Anchored off). Model → Create → Hinge: click first on the top of the base, then on the bottom of the bar.
An Attachment's rotation axis is the yellow arrow. Rotate both Attachments so the arrows point up (Orientation 0, 0, 90).
HingeConstraint: ActuatorType = Motor, AngularVelocity = 1.5 (speed), MotorMaxTorque = 100000000 — otherwise a player stops the bar. The workbook used a CylindricalConstraint — a Hinge does the same, just simpler.
Spring: "SpringBase" (Anchored on) and a pad "Pad" above it (Anchored off). Model → Create → Spring between them: Stiffness 2000, FreeLength — the distance between them, Damping 50.
To keep the pad from drifting sideways, add a Prismatic (a guide rail) between the same parts. Both Attachments arrow up.
Pendulum: "PendulumTop" up high (Anchored on), a ball "Ball" off to the side (Anchored off, Shape Ball). Model → Create → Rope between them, Length a bit longer than the distance. Released from the side, the ball starts swinging by itself.
Make the ball heavy: CustomPhysicalProperties on, Density 10 — it will knock players off.
Over time the pendulum and spring stop or get knocked out of place by players — "ResetScript" puts the part back with no speed every 30 seconds and it all starts over.
Scripts
ResetScript
Where: Workspace → Pendulum → Ball (and Trampoline → Pad) · Script Why: Puts the part back in place.
-- the pendulum or the spring pad
local part = script.Parent
-- how often (in seconds) to reset it
local RESET_TIME = 30
-- position and rotation at the start of the game
local start = part.CFrame
-- forever
while true do
-- wait
task.wait(RESET_TIME)
-- stop the movement
part.AssemblyLinearVelocity = Vector3.zero
-- stop the spinning
part.AssemblyAngularVelocity = Vector3.zero
-- put it back — the pendulum swings again
part.CFrame = start
-- end of loop
end
Testing
Press Play (or Run) and make sure:
The bar spins; a player it hits flies off the platform.
Stand on the spring pad — it sinks and bounces back.
The ball swings across the path; after 30 seconds it starts again from the original point.