@@ -4,50 +4,50 @@ Authors:
44 veryunhappydoge; roblox: 1455906620, github: dowoge
55
66 note: this will not work at all if targetDir is not set correctly, please verify that the directory path is valid
7- ]]
8-
9- local curCam = game .Workspace .CurrentCamera -- player's camera instance
10-
11- local targetDir = game .Workspace .swayDirectory -- this is the group, folder, or directory of all the parts this will affect; do the sway
12- -- change this value to where it actually is
13-
14- local distance = 50 -- max distance for visual effects to happen (in studs)
15-
16- -- this is the part names for what you want these to affect specifically
17- local names = {
18- ' bigTree' ,
19- ' medTree' ,
20- ' smallTree' ,
21- ' plant' ,
22- }
23- -- the amplitude of the movement (smaller = moves more, bigger = moves less)
24- local amps = {
25- bigTree = { 25 , 50 },
26- medTree = { 15 , 30 },
27- smallTree = { 12.5 , 25 },
28- plant = { 5 , 10 },
29- }
30- -- main sway function
31- function SwayPart (part )
32- if table .find (names , part .Name ) then
33- local PartCF = part .CFrame
34- local pos = PartCF .p
35- local tall = part .Size .Y
36- game :GetService (' RunService' ).Stepped :connect (function ()
37- local _ , isOnScreen = curCam :WorldToViewportPoint (part .Position )
38- if ((curCam .CFrame .p - part .Position ).Magnitude <= distance ) and isOnScreen then
39- local T = tick ()
40- local x = (math.sin (T + (pos .x / amps [part .Name ][1 ])) * math.sin (T / amps [part .Name ][2 ])) / amps [part .Name ][1 ]
41- local z = (math.sin (T + (pos .z / amps [part .Name ][1 ])) * math.sin (T / amps [part .Name ][2 ])) / amps [part .Name ][1 ]
42- part .CFrame = (PartCF + Vector3 .new (x , 0 , z )) * CFrame .Angles (z / tall , 0 , x / - tall )
43- end
44- end )
45- end
46- end
47-
48- -- operate
49- for _ , v in pairs (targetDir :GetChildren ()) do
50- if v :IsA (' BasePart' ) then
51- SwayPart (v )
52- end
53- end
7+ ]]
8+
9+ local curCam = game .Workspace .CurrentCamera -- player's camera instance
10+
11+ local targetDir = game .Workspace .swayDirectory -- this is the group, folder, or directory of all the parts this will affect; do the sway
12+ -- change this value to where it actually is
13+
14+ local distance = 50 -- max distance for visual effects to happen (in studs)
15+
16+ -- this is the part names for what you want these to affect specifically
17+ local names = {
18+ ' bigTree' ,
19+ ' medTree' ,
20+ ' smallTree' ,
21+ ' plant' ,
22+ }
23+ -- the amplitude of the movement (smaller = moves more, bigger = moves less)
24+ local amps = {
25+ bigTree = { 25 , 50 },
26+ medTree = { 15 , 30 },
27+ smallTree = { 12.5 , 25 },
28+ plant = { 5 , 10 },
29+ }
30+ -- main sway function
31+ function SwayPart (part )
32+ if table .find (names , part .Name ) then
33+ local PartCF = part .CFrame
34+ local pos = PartCF .p
35+ local tall = part .Size .Y
36+ game :GetService (' RunService' ).Stepped :connect (function ()
37+ local _ , isOnScreen = curCam :WorldToViewportPoint (part .Position )
38+ if ((curCam .CFrame .p - part .Position ).Magnitude <= distance ) and isOnScreen then
39+ local T = tick ()
40+ local x = (math.sin (T + (pos .x / amps [part .Name ][1 ])) * math.sin (T / amps [part .Name ][2 ])) / amps [part .Name ][1 ]
41+ local z = (math.sin (T + (pos .z / amps [part .Name ][1 ])) * math.sin (T / amps [part .Name ][2 ])) / amps [part .Name ][1 ]
42+ part .CFrame = (PartCF + Vector3 .new (x , 0 , z )) * CFrame .Angles (z / tall , 0 , x / - tall )
43+ end
44+ end )
45+ end
46+ end
47+
48+ -- operate
49+ for _ , v in pairs (targetDir :GetChildren ()) do
50+ if v :IsA (' BasePart' ) then
51+ SwayPart (v )
52+ end
53+ end
0 commit comments