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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Gunroar:Cannon()
Party member
Posts: 204
Joined: Thu Dec 10, 2020 1:57 am

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

Pls fix this.. Should point to target (touch) and draw accordingly pls
rotation.love
The love file
Last edited by Gunroar:Cannon() on Tue Jan 19, 2021 10:20 pm, edited 4 times in total.
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

4vZEROv
Party member
Posts: 117
Joined: Wed Jan 02, 2019 8:44 pm

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

The least you can do if you want some help it to explain what you want to do, your message is very disrespectful ...
Gunroar:Cannon()
Party member
Posts: 204
Joined: Thu Dec 10, 2020 1:57 am

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

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.)
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

Xii
Citizen
Posts: 83
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

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

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.
pgimeno
Party member
Posts: 2555
Joined: Sun Oct 18, 2015 2:58 pm

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

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.
Gunroar:Cannon()
Party member
Posts: 204
Joined: Thu Dec 10, 2020 1:57 am

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

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
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow


### Who is online

Users browsing this forum: Toad Venture and 19 guests