[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
Before you make a thread asking for help, read this.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 207
Joined: Thu Dec 10, 2020 1:57 am

[Solved]Rotating and drawing object to target correctly

Post 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 124 times
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
User avatar
4vZEROv
Party member
Posts: 117
Joined: Wed Jan 02, 2019 8:44 pm

Re: Rotating and drawing object to target correctly

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

Re: Rotating and drawing object to target correctly

Post 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.)
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
User avatar
Xii
Citizen
Posts: 83
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Rotating and drawing object to target correctly

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

Re: Rotating and drawing object to target correctly

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

Re: Rotating and drawing object to target correctly

Post 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:
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
Post Reply

Who is online

Users browsing this forum: pgimeno and 18 guests