I know, that's why im inpitting tryY - y and tryX - x
rotation question
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: rotation question
Here you go, quick and dirty:
Code: Select all
function love.load()
love.mouse.setVisible(false)
lAngle = -90
dAngle = 0
end
function love.draw()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.ellipse("fill", mX, mY, 4, 4)
love.graphics.ellipse("fill", 400, 200, 10, 10)
love.graphics.setColor(255, 0, 0, 255)
lX = 400 + 100 * math.cos(math.rad(lAngle))
lY = 200 + 100 * math.sin(math.rad(lAngle))
love.graphics.line(400, 200, lX, lY)
at2 = math.deg(math.atan2(mY-200, mX-400))
love.graphics.print(at2 , mX, mY)
if lAngle < at2 and mY < 200 then
dAngle = 0.5
else
dAngle = -0.5
end
lAngle = lAngle + dAngle
end
function love.update(dt)
mX, mY = love.mouse.getPosition()
end
-
- Prole
- Posts: 10
- Joined: Sat Dec 16, 2017 8:34 pm
Re: rotation question
But the problem I still there :\mr_happy wrote: ↑Sun Dec 17, 2017 5:54 pm Here you go, quick and dirty:
Code: Select all
function love.load() love.mouse.setVisible(false) lAngle = -90 dAngle = 0 end function love.draw() love.graphics.setColor(255, 255, 255, 255) love.graphics.ellipse("fill", mX, mY, 4, 4) love.graphics.ellipse("fill", 400, 200, 10, 10) love.graphics.setColor(255, 0, 0, 255) lX = 400 + 100 * math.cos(math.rad(lAngle)) lY = 200 + 100 * math.sin(math.rad(lAngle)) love.graphics.line(400, 200, lX, lY) at2 = math.deg(math.atan2(mY-200, mX-400)) love.graphics.print(at2 , mX, mY) if lAngle < at2 and mY < 200 then dAngle = 0.5 else dAngle = -0.5 end lAngle = lAngle + dAngle end function love.update(dt) mX, mY = love.mouse.getPosition() end
Wait until the line is at about 1 o'clock, and then put the curser at about 4 o'clock. Instead of going the shortest route(1, 2, 3, 4), the line spins around(1, 12, 11, 10, 9, 8, 7, 6, 5, 4).
Re: rotation question
I did type this in blind... Um, just look at the logic at the end of love.draw() , its in that area!
Re: rotation question
Something like this?
Ops, wrong file.
Ops, wrong file.
Last edited by Ref on Sun Dec 17, 2017 6:49 pm, edited 1 time in total.
Re: rotation question
Now at computer with love installed. This does the trick (but still quick and dirty)...
Code: Select all
function love.load()
love.mouse.setVisible(false)
lAngle = 90
dAngle = 0
end
function love.draw()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.ellipse("fill", mX, mY, 4, 4)
love.graphics.ellipse("fill", 400, 200, 10, 10)
love.graphics.setColor(255, 0, 0, 255)
lX = 400 + 100 * math.cos(math.rad(lAngle))
lY = 200 + 100 * math.sin(math.rad(lAngle))
love.graphics.line(400, 200, lX, lY)
at2 = math.deg(math.atan2(mY-200, mX-400))
diff = lAngle -at2
if diff > 360 then diff = diff - 360 end
love.graphics.print(diff , mX, mY)
if diff > 180 or diff < 0 then
dAngle = 0.5
else
dAngle = -0.5
end
lAngle = lAngle + dAngle
end
function love.update(dt)
mX, mY = love.mouse.getPosition()
end
function love.keypressed(key)
if key == 'escape' then love.event.quit() end
end
Re: rotation question
And you did have params wrong way round in your code:
io.write(i, ' : ', math.atan2(x, y), '\t')
io.write(i, ' : ', math.atan2(x, y), '\t')
Re: rotation question
EDIT Still not right (lol) missed another check, shoudl be ok now:
Code: Select all
function love.load()
love.mouse.setVisible(false)
lAngle = 90
dAngle = 0
end
function love.draw()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.ellipse("fill", mX, mY, 4, 4)
love.graphics.ellipse("fill", 400, 200, 10, 10)
love.graphics.setColor(255, 0, 0, 255)
lX = 400 + 100 * math.cos(math.rad(lAngle))
lY = 200 + 100 * math.sin(math.rad(lAngle))
love.graphics.line(400, 200, lX, lY)
at2 = math.deg(math.atan2(mY-200, mX-400))
diff = lAngle -at2
if diff > 360 then diff = diff - 360 end
if diff < -180 then diff = diff + 360 end
love.graphics.print(diff , mX, mY)
if diff >= 180 or diff < 0 then
dAngle = 0.5
else
dAngle = -0.5
end
lAngle = lAngle + dAngle
end
function love.update(dt)
mX, mY = love.mouse.getPosition()
end
function love.keypressed(key)
if key == 'escape' then love.event.quit() end
end
-
- Prole
- Posts: 10
- Joined: Sat Dec 16, 2017 8:34 pm
Re: rotation question
Thanks, works now!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests