Page 1 of 1

### [Solved]Rotating and drawing object to target correctly

Posted: Mon Jan 18, 2021 12:44 am
Pls fix this.. Should point to target (touch) and draw accordingly pls
rotation.love
The love file

### Re: Rotating and drawing object to target correctly

Posted: Mon Jan 18, 2021 9:07 pm
The least you can do if you want some help it to explain what you want to do, your message is very disrespectful ...

### Re: Rotating and drawing object to target correctly

Posted: Tue Jan 19, 2021 6:25 am
Disrespectful? I do not know what you are talking about?
also me: *changes message *
(sorry, I was in a rush as you could have seen from the the spelling mistake so I didn't have much time.)

### Re: Rotating and drawing object to target correctly

Posted: Tue Jan 19, 2021 8:52 am
The perception of disrepsect likely stems from "here's my whole project, someone fix it for me please".
To request for community assistance, you should provide minimal code that illustrates your problem, explain what it is you're trying to accomplish, and what your own best approach so far has been.

### Re: Rotating and drawing object to target correctly

Posted: Tue Jan 19, 2021 10:13 am
It's a pretty minimal example, but yeah, the attitude...

Looking into the code, it looks to me that the main problem is the overcomplicating of formulas, resulting in incorrect output (like, pi squared??), and the improper use of origin x and y (confusion of variables, it uses the one for v instead of the one for m).

After removing the *-1 from the angle calculation, this works for me:

Code: Select all

``````    love.graphics.draw(v, self.x, self.y, 0, vw, vh, xx, yy)
love.graphics.draw(m, self.x, self.y, self.angle, mw, mh, mx/2, my/2)
``````
The screw eye is at the centre of the images, so that's where the coordinates should point.

### Re: Rotating and drawing object to target correctly

Posted: Tue Jan 19, 2021 1:28 pm
I wasn't trying to be disrespectful ... I was just in a rush and thought it was pretty self-explainatory. Anyway that's like less than 10% of my main project . Plus you can see my tries( math.pi^2 ) and I kept reshuffling tries but couldn't get it. So I say thnx to you all for taking the time to look at my code and Thnx for the solution. I'll check it soon, thnx!
Edited: So I checked it and it worked , yay! I removed the negative sign from Turret:getAngle and since I wanted the muzzle(?) to rotate at the center of the box I made the x origin 0:

Code: Select all

`` love.graphics.draw(m, self.x, self.y, self.angle, mw, mh, 0, my/2)``
or something like that