Image angle to mouse?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
BluBillz
Prole
Posts: 46
Joined: Tue Oct 29, 2013 6:02 pm

Image angle to mouse?

Post by BluBillz »

I am trying to make this image of the letter L basically rotate its angle by where the mouse position of Y is. The way I have it setup makes it rotate uncontrollably fast and also rotates around the back of the L when I want it to rotate up/down from the top of the L. I do have source to show you what it does..How could I fix this so the image can rotate up/down with the mouse? also code below too. :halloween:

Code: Select all

function love.load()

love.graphics.setBackgroundColor(0,200,200)

  x = love.graphics.getWidth() / 2
  y = love.graphics.getHeight() / 2

letter = love.graphics.newImage("letter.png")

end

Code: Select all

function love.update(dt)

	mx, my = love.mouse.getPosition()

end

Code: Select all

function love.draw()

love.graphics.setColor(255, 255, 255)

love.graphics.draw(letter,x,y,my)

end
Attachments
imageAngle2Mouse.zip
(876 Bytes) Downloaded 103 times
User avatar
nfey
Citizen
Posts: 63
Joined: Tue Feb 18, 2014 9:50 am
Location: Romania

Re: Image angle to mouse?

Post by nfey »

The fourth parameter of love.graphics.draw() is the orientation and needs to be given in radians.
You are giving it one half of a coordinate on the screen, the Y part. Which is a distance measured in pixels. You're not giving it the correct value.
https://www.love2d.org/wiki/love.graphics.draw

You need to:
- calculate the distance between the letter's position and the mouse position
- calculate the angle between this line and the horizontal

You can achieve this using basic trigonometry.
Do you want the letter to rotate instantly according to mouse movement? Or do you want the letter to rotate incrementally with a certain speed (so that, if the mouse moves really fast, the letter will lag behind)?
User avatar
BluBillz
Prole
Posts: 46
Joined: Tue Oct 29, 2013 6:02 pm

Re: Image angle to mouse?

Post by BluBillz »

nfey wrote:Or do you want the letter to rotate incrementally with a certain speed (so that, if the mouse moves really fast, the letter will lag behind)?
Yes I want to do that but how would I code that? It is what I am asking because I don't know honestly how that would work.
Post Reply

Who is online

Users browsing this forum: No registered users and 252 guests