Page 1 of 1

[Solved]Rotating and drawing object to target correctly

Posted: Mon Jan 18, 2021 12:44 am
by Gunroar:Cannon()
Pls fix this.. Should point to target (touch) and draw accordingly pls :P
rotation.love
The love file
(7.46 KiB) Downloaded 208 times

Re: Rotating and drawing object to target correctly

Posted: Mon Jan 18, 2021 9:07 pm
by 4vZEROv
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
by Gunroar:Cannon()
Disrespectful? I do not know what you are talking about? :P :)
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
by Xii
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
by pgimeno
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
by Gunroar:Cannon()
I wasn't trying to be disrespectful :cry: ... I was just in a rush :cry: and thought it was pretty self-explainatory. Anyway that's like less than 10% of my main project :megagrin: . Plus you can see my tries( math.pi^2 :cry: ) 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 :megagrin: