bullet directions

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
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

bullet directions

Post 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 !!!!!!!!!!!!!!!
szensk
Party member
Posts: 155
Joined: Sat Jan 19, 2013 3:57 am

Re: bullet directions

Post 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!
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: bullet directions

Post by Davidobot »

Here is a wiki page about bullets: https://love2d.org/wiki/Tutorial:Fire_Toward_Mouse
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: bullet directions

Post by pielago »

Nice work!
and sure ill check it out and thanks for the examples...
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: bullet directions+stand

Post 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
Attachments
bullets.love
(3.31 KiB) Downloaded 73 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest