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

Why is my rotation being set to math.huge?!?

Asked by 9 years ago

So, earlier today, I made a script that would draw a Gui line between two points. It works pretty well, but problem is, the closer the two points are, the less accurate the line is. At a certain point, the line's rotation is for some reason set to Infinite. I honestly have no idea why this is happening.

alright, to set up,

use the following model and mess with the point positions. http://www.roblox.com/Line-graph-stuff-item?id=175365940

Heres the script :

function sin(num)
    return math.sin(num)
end

function asin(num)
return math.asin(num)
end


function drawline(point1,point2,thickness) -- currently working with pixels, not scale
    local line = Instance.new("Frame")
    line.Name = "line"
    line.Parent = script.Parent

    local xpos1 = point1.X.Offset
    local ypos1 = point1.Y.Offset
    local xpos2 = point2.X.Offset
    local ypos2 = point2.Y.Offset

local distx = math.abs((xpos1 - xpos2))
local disty = math.abs((ypos1 - ypos2))

print(distx,disty)
--                     ||
--direction logic here \/

local direction 
if ypos1 >= ypos2 then

    direction = 1
    print("Going Up")
else
    direction = -1
    print("Going Down")
end
if direction == 1 then
line.Position = UDim2.new(0,(xpos1 + (distx /2)),0,(ypos1 - (disty /2)))
else
line.Position = UDim2.new(0,(xpos1 + (distx /2)),0,(ypos1 + (disty /2)))

end

local oa = disty/distx
local angle = asin(oa)
print(math.deg(angle))
local zdist = (distx^2 + disty^2)^.5
print(zdist)
line.Size = UDim2.new(0,zdist,0,10)
line.Position = line.Position - UDim2.new(0,zdist/2,0,thickness)

line.Rotation = 180-((math.deg(angle))* direction)
end



drawline(script.Parent["#1"].Position,script.Parent["#2"].Position,3)

any help or ideas are strongly appreciated!

1 answer

Log in to vote
0
Answered by 9 years ago

print(2/0 == math.huge) --> true

Division by 0 can't be, Roblox just going to return math.huge instead of error I think this is the reason why rotation is math.huge Maybe try to check line 43?

Ad

Answer this question