Page 1 of 1

bullet directions

Posted: Tue Aug 27, 2013 5:01 am
by pielago
Hi guys
I see many tutorials about bullets BUT they are with the mouse direction!!
bullets follow the mouse pointers..
now can someone tell me how to use bullets but with one key to trigger?
for example a player moves up with (w) down with (s) right with (a) and finally left with (d)
and (k) would be the fire button...
now how do i do it? for one key to fire different directions?

if my player is facing up use K to fire or if the player its facing down still use K to fire
i used variables likes
left ="left"
but still didn't work
can someone tell me?? thank you !!!!!!!!!!!!!!!

Re: bullet directions

Posted: Tue Aug 27, 2013 5:14 am
by szensk
you're going to want to store the facing direction of the player, that is: store the last direction that you moved the player then multiply the bullet's velocity vector by the direction vector. this is untested and is just here to show you the intent.

Code: Select all

local dir = { x = 0, y = 0 } --dont make a table every loop though
if love.keyboard.isDown('up') then 
   dir.y = -1
elseif love.keyboard.isDown('down') then 
   dir.y = 1
end
if love.keyboard.isDown('left') then 
   dir.x = -1
elseif love.keyboard.isDown('right') then
   dir.x =  1
end
makeNewBullet(100 * dir.x, 100 * dir.y) --it's fast!

Re: bullet directions

Posted: Tue Aug 27, 2013 9:47 am
by Davidobot
Here is a wiki page about bullets: https://love2d.org/wiki/Tutorial:Fire_Toward_Mouse

Re: bullet directions

Posted: Sat Aug 31, 2013 8:54 am
by pielago
Nice work!
and sure ill check it out and thanks for the examples...

Re: bullet directions+stand

Posted: Tue Apr 15, 2014 12:27 am
by pielago
I have a small problem hope someone could help me
i can create bullets now and shoot them , can shoot right,left,up,down

after a few seconds i want stand to overwrite all the states so i can use state=stand for other things but it seem
like stand disappears while bullets are pressed or not i still want to use state= stand but how?????

I am sure its something small to fix but maybe i haven't seen it :(

here its the .love