I am trying to make a tornado damage script and it works (kind of) but all parts hit by a tornado go to the same spot and I don't know how I could fix this even by looking at multiple CFrame tutorials. pls help pretty pls
video showing problem: https://streamable.com/cbfs9m
code:
local tornado = script.Parent local tornadoOffset = CFrame.new(0, 0, tornado.Position.Z * 10) tornado.Touched:Connect(function(hit) if hit.Name ~= "Baseplate" then hit.Anchored = false local damage = Instance.new("BodyPosition", hit) damage.MaxForce = Vector3.new(math.huge, math.huge, math.huge) while wait() do damage.Position = tornado.CFrame:ToWorldSpace(tornadoOffset).p end end end)
local RAD_MAX = 10 local angle = math.rad(math.random(360)) local radius = RAD_MAX * math.random(-1000, 1000) / 1000 local randOffset = Vector3.new(math.cos(angle), 0, math.sin(angle)) * radius local tornadoOffset = CFrame.new(tornado.Position + randOffset)
the offset is a random position in the circle around the tornado with a radius of RAD_MAX. you can also mess around with the height and rotation of CFrames to make it “truly” random. if you don’t understand the math, I think it is important that you do, so I suggest you look up how to find a point on a circle.
Instead of multiplying the Z by 10, I would use math.random(10)
, which chooses a random number between 1 and 10 and multiplies it with the Z.