Page 1 of 1

Offsetting where a projectile is fired from

Posted: Wed Jul 16, 2014 7:32 am
by Sakonosolo
I'm just kind of messing around with the engine right now trying to get a feel for it so I'm looking through tutorials and stuff. What I'm doing right now is trying to make a small little top down shooter. I have my little guy and have projectiles firing (haven't gotten to destroying them when they get to the edge of the screen though) but the issue I'm having is that every tutorial I can find on firing projectiles makes it so the projectiles spawn from the middle of your character. What I want to do is have the projectiles spawn at the end of the "turret" of my guy rather than in the center. I've been trying to get a handle of the trig of doing these kinds of things (for example you need to use the atan2 function to make a character follow your mouse) but it's a lot more difficult if I don't know what exactly I'm trying to find. Through my attempts I've gotten it so that at most, 2 angles of firing work fine, but at any other angles the bullets don't even spawn anywhere near my guy.

Here's my .love file.

https://dl.dropboxusercontent.com/u/487 ... 0Test.love

Also, is there a way to cap your framerate without using vsync? Just curious.

Re: Offsetting where a projectile is fired from

Posted: Wed Jul 16, 2014 10:31 am
by Jimanzium
Hello, this is quite easy to do.

Code: Select all

local turretLength = 45
function shoot()
	-- stuff
	local spawnX = playerX + math.cos(angle) * turretLength
	local spawnY = playerY + math.sin(angle) * turretLength
end
And for limiting frame rate

Code: Select all

function love.update(dt)
   if dt < 1/30 then
      love.timer.sleep(1/30 - dt)
   end
end
Taken from http://love2d.org/wiki/love.timer.sleep. This would limit the frame rate to 30

Re: Offsetting where a projectile is fired from

Posted: Wed Jul 16, 2014 6:54 pm
by Sakonosolo
I swear that I put that exact code in yesterday (though I used 65 instead of 45 since that's the distance from the center of the character to the end of the turret) and it didn't work. I did notice just now that I originally put in math.cos for both when implementing your code though so it's possible that that's where I went wrong yesterday. I'll have to see if this code is as simple for more complex characters instead of just a box with a rectangle on it.

And cool, I was more thinking there would be a built in function already for limiting the framerate but I guess I could just make one myself. Thanks.

Re: Offsetting where a projectile is fired from

Posted: Wed Jul 16, 2014 7:40 pm
by Jeeper
Why on earth would you want to limit the fps?

Re: Offsetting where a projectile is fired from

Posted: Wed Jul 16, 2014 8:21 pm
by Sakonosolo
Perhaps if in a game I make I want to have a built in framerate limiter that doesn't use vsync. Vsync introduces some slight lag which could be undesirable. If I don't want that lag while testing a game then I disable it but then the game is running at potentially 1000+ fps which isn't good for my GPU. So limiting the framerate to 60 fps or any other number would help me work without the input lag but also not fry my GPU with it trying to output thousands of frames every second.