-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBodyTransform.lua
127 lines (68 loc) · 1.92 KB
/
BodyTransform.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module("shadows.BodyTransform", package.seeall)
Transform = require("shadows.Transform")
BodyTransform = setmetatable( {}, Transform )
BodyTransform.__index = BodyTransform
BodyTransform.__type = "BodyTransform"
BodyTransform.DestroyAttachments = false
BodyTransform.FollowPosition = true
BodyTransform.FollowRotation = true
function BodyTransform:new(Body)
if Body then
local self = setmetatable( {}, BodyTransform )
self.Body = Body
self.Children = {}
self.Matrix = { {}, {} }
self.InverseMatrix = { {}, {} }
self:SetLocalRotation(0)
return self
end
end
function BodyTransform:Update()
if self.Body then
if self.Body:isDestroyed() then
self:Remove()
else
if self.FollowPosition then
self:SetLocalPosition( self.Body:getPosition() )
end
if self.FollowRotation then
self:SetLocalRotation( math.deg( self.Body:getAngle() ) )
end
end
end
end
function BodyTransform:Remove()
if self.World then
self.World.BodyTracks[self.TransformID] = nil
self.World = nil
self.TransformID = nil
for Index, Child in pairs(self.Children) do
if self.DestroyAttachments then
if Child.Object then
Child.Object:Remove()
end
end
Child:SetParent(nil)
end
self:SetParent(nil)
end
end
function BodyTransform:SetDestroyAttachments(DestroyAtachments)
self.DestroyAttachments = DestroyAttachments
end
function BodyTransform:GetDestroyAttachments()
return self.DestroyAttachments
end
function BodyTransform:SetFollowPosition(FollowPosition)
self.FollowPosition = FollowPosition
end
function BodyTransform:GetFollowPosition()
return self.FollowPosition
end
function BodyTransform:SetFollowRotation(FollowRotation)
self.FollowRotation = FollowRotation
end
function BodyTransform:GetFollowRotation()
return self.FollowRotation
end
return BodyTransform