Skip to content

Commit b754b1a

Browse files
authored
Add files via upload
1 parent e62b75a commit b754b1a

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

Constraints.lua

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
-- Pepsi Was Here [Some imperfect constraint templates]
2+
-- Creates a new ghost part that goes through walls and locks onto another part. Typically used for one-way forces.
3+
local function CreateProxy(Part)
4+
local AttachmentPart = Instance.new("Attachment")
5+
local Proxy = Instance.new("Part", AttachmentPart)
6+
Proxy.Archivable = false
7+
Proxy.CanCollide = false
8+
Proxy.CanQuery = false
9+
Proxy.CanTouch = false
10+
Proxy.Massless = true
11+
Proxy.Size = Vector3.zero
12+
Proxy.Transparency = 1
13+
local AlignPosition = Instance.new("AlignPosition", Proxy)
14+
AlignPosition.Archivable = false -- Please note that when Archivable is disabled, the instance cannot be cloned, and WONT save when you close studio. Feel free to set to true (its default value)
15+
AlignPosition.Attachment0 = Instance.new("Attachment", Proxy)
16+
AlignPosition.Attachment1 = AttachmentPart
17+
AlignPosition.MaxForce, AlignPosition.Responsiveness = math.huge, 200
18+
AttachmentPart.Parent = Part
19+
return Proxy, AttachmentPart
20+
end
21+
22+
-- https://create.roblox.com/docs/reference/engine/classes/AlignPosition
23+
-- Applies force to Part in the direction to Goal.
24+
local function AlignTo(Part, Goal, Rate, Responsiveness)
25+
local AttachmentPart = Instance.new("Attachment")
26+
local AlignPosition = Instance.new("AlignPosition", AttachmentPart)
27+
AlignPosition.Archivable = false
28+
AlignPosition.MaxForce = math.huge
29+
AlignPosition.Responsiveness = Responsiveness or 200
30+
AlignPosition.MaxVelocity = Rate or 20
31+
AlignPosition.Attachment0 = AttachmentPart
32+
AlignPosition.Attachment1 = Instance.new("Attachment", Goal)
33+
AttachmentPart.Parent = Part
34+
return AlignPosition
35+
end
36+
37+
-- https://create.roblox.com/docs/reference/engine/classes/RodConstraint
38+
-- Creates a rod constraint and locks the distance between Part1 and Part2.
39+
local function ConnectRod(Part1, Part2, Length) -- Wish there was a winch setting for rods, too. :(
40+
local Attachment1 = Instance.new("Attachment")
41+
Attachment1.Archivable = false
42+
43+
local Attachment2 = Instance.new("Attachment")
44+
Attachment2.Archivable = false
45+
Attachment1.Parent, Attachment2.Parent = Part2, Part1
46+
47+
local Rod = Instance.new("RodConstraint")
48+
Rod.Archivable = false
49+
--Rod.Visible = true -- Used for visually seeing the rope
50+
Rod.Thickness = 0.1
51+
Rod.Length = Length or 10
52+
Rod.Attachment0, Rod.Attachment1 = Attachment1, Attachment2
53+
Rod.Parent = Attachment1
54+
return Rod
55+
end
56+
57+
-- https://create.roblox.com/docs/reference/engine/classes/RopeConstraint
58+
-- Creates a rope constraint that uses less forceful means to keep a distance. Unlock the rod, a rope's distance can be less than it's length. While a rod will not let you go further nor closer.
59+
local function ConnectRope(Part1, Part2, Length, Speed, Slack) -- Tip: This could be used as a tween without TweenService!
60+
local Attachment1 = Instance.new("Attachment")
61+
Attachment1.Archivable = false
62+
63+
local Attachment2 = Instance.new("Attachment")
64+
Attachment2.Archivable = false
65+
Attachment1.Parent, Attachment2.Parent = Part2, Part1
66+
67+
local Rope = Instance.new("RopeConstraint")
68+
Rope.Archivable = false
69+
-- Rope.Visible = true -- Again used to visually see the rope.
70+
Rope.Thickness = 0.1
71+
Rope.Length = Slack or 40
72+
Rope.WinchEnabled = true -- Set to false if you JUST want a rope that doesn't try to pull anything in.
73+
Rope.WinchTarget = Length
74+
Rope.WinchForce = math.huge
75+
Rope.WinchSpeed = Speed or 25
76+
--Rope.Restitution = ? -- may help with going trough walls at high speeds. Set to what ever is best for your use
77+
Rope.Attachment0, Rope.Attachment1 = Attachment1, Attachment2
78+
Rope.Parent = Attachment1
79+
return Rope
80+
end

0 commit comments

Comments
 (0)