So im trying to create an animated tree script for my trees yet my script is unable to account for the current rotation of the tree.
I would like to animate here: http://prntscr.com/nqp0zn
Yet it changes it to here: http://prntscr.com/nqp17f
Here is my code that I am using.
local treepos = script.Parent.Position treepos = Vector3.new(treepos.x, treepos.y-0.2, treepos.z) local x = 0 local z = 0 local T = -99999 local tall = script.Parent.Size.Y / 2 local rand = (math.random(0,20))/10 while true do x = treepos.x + (math.sin(T + (treepos.x/5)) * math.sin(T/9))/3 z = treepos.z + (math.sin(T + (treepos.z/6)) * math.sin(T/12))/4 script.Parent.CFrame = CFrame.new(x, treepos.y, z) * CFrame.Angles((z-treepos.z)/tall, 0,(x-treepos.x)/-tall) wait() T = T + 0.12 end
Any help is greatly appreciated!
Hope this helps...
local treepos = script.Parent.Position treepos = Vector3.new(treepos.x, treepos.y-0.2, treepos.z) local x = 0 local z = 0 local T = -99999 local tall = script.Parent.Size.Y / 2 local rand = (math.random(0,20))/10 memory = script.Parent.CFrame while true do x = (math.sin(T + (treepos.x/5)) * math.sin(T/9))/3 z = (math.sin(T + (treepos.z/6)) * math.sin(T/12))/4 script.Parent.CFrame = (memory + Vector3.new(x, 0, z)) * CFrame.Angles(z/tall, 0,x/-tall) wait() T = T + 0.12 end
Edit: I forgot to adjust CFrame.Angles. Its getting really late in UK.