Code: Select all
function draw_line_at_angle(x, y, angle, length)
<calculation>
love.graphics.line(x, y, xx, yy)
end
Code: Select all
function draw_line_at_angle(x, y, angle, length)
<calculation>
love.graphics.line(x, y, xx, yy)
end
Trigonometry!Ripe wrote:Hello guys! I've been playing around with love for a couple of days now I've came into my first problem and I'm hoping someone could help me out. I'm trying to create a function that will draw a line from a given x, y position on set angle for a certain distance. I would imagine it'll look something like this;
I tried doing a sort of right angle triangle calculation by using length as c and angle as A but it didn't work out to well. Does anyone have any ideas?Code: Select all
function draw_line_at_angle(x, y, angle, length) <calculation> love.graphics.line(x, y, xx, yy) end
Code: Select all
local xx = x + math.cos(math.rad(angle)) * length -- math.rad converts degrees to radians
local yy = y + math.sin(math.rad(angle)) * length
love.graphics.line(x, y, xx, yy)
Users browsing this forum: Google [Bot] and 2 guests