Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What do these math equations mean?

Asked by 5 years ago

I am looking over a script my friend made that shoots out a lightning bolt to wherever your mouse cursor is. Most of it makes sense, however some of the math I can't quite comprehend. Script --I'm only including the function that matters, I will put comments next to math variables I do or don't understand. Also correct me if some of my comments are inaccurate.

function Lightning(pos,pos2,radius,numParts,model)  --Example Arguments: Lightning(plr.Character["LeftHand"].CFrame.p, mousehit.p, 0.15, 6, workspace)
    radius = radius or 0.2 
    numParts = numParts or 10
    model = model or workspace
    local lv = CFrame.new(pos,pos2).lookVector --Positions the bolt in your general vicinity
    local dist = (pos-pos2).magnitude -- Creates a straight line (bolt) between mouse position and you
    local dbp = dist/numParts --Divides the bolt into segments(numParts)
    local last = pos --I think this does something later
    for i = 1,numParts do
        local p = Instance.new("Part",model)
        p.FormFactor = "Symmetric"
        p.Size = Vector3.new(1,1,1)
        p.CanCollide = false
        p.Material = "Neon"
        p.Transparency = 0.5
        p.Anchored = true
        p.BrickColor = BrickColor.new("Bright red")
        local x = math.random(-100,100)/100*dbp/2 --?????
        local y = math.random(-100,100)/100*dbp/2 --?????
        local p2 = CFrame.new(pos+lv*(i*dbp),pos2+lv)*CFrame.new(x,y,0) --?????
        local dist2 = (p2.p-last).magnitude
        local mid = (p2.p+last)/2 
        local m = Instance.new("BlockMesh",p) --Why add a mesh??
        m.Scale = Vector3.new(radius,radius,dist2) 
        p.CFrame = CFrame.new(mid,p2.p) 
        last = p2.p
        game:GetService("Debris"):AddItem(p,math.random(40,100)/1000)
    end
end

The ones with the ????? are the primary cause of confusion, everything else is just minor.

0
Okay wait, I think you need to call the function in order to see what happens, pos,pos2,radius,numparts and model are all in the parameter, you need to define them when calling the function greatneil80 2647 — 5y
0
Also, thats simple multiplication and addition to move to position of the object greatneil80 2647 — 5y
0
Your friend needs to get out of 2008 lol. User#19524 175 — 5y
0
I did define them, but I didnt add them, like I said I only included the function that mattered, so instead I just put an example next to the parameters. DominousSyndicate 41 — 5y
View all comments (2 more)
0
What did that have to do with my comment. User#19524 175 — 5y
0
lol @incapaz. I agree. 2008 is dead. We are in 2018 now. User#21908 42 — 5y

Answer this question