Tutorial on bullets?

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
BEANSFTW
Prole
Posts: 28
Joined: Sun Apr 15, 2012 2:58 pm

Tutorial on bullets?

Post by BEANSFTW »

Can someone give me a tutorial on a basic bullet? I've seen many other tutorials about this, but they all seem too rushed.
User avatar
severedskullz
Prole
Posts: 36
Joined: Thu May 30, 2013 1:55 am

Re: Tutorial on bullets?

Post by severedskullz »

Need more info on what you need. Are you launching bullets from turrets, guns, players, etc. Is Rotation a factor in your implementation? Are there dynamic offsets of the bullets location? Is the bullet "homing" in on its target?
User avatar
BEANSFTW
Prole
Posts: 28
Joined: Sun Apr 15, 2012 2:58 pm

Re: Tutorial on bullets?

Post by BEANSFTW »

The game is a top down view. You can click the mouse somewhere, and the player will fire the bullet in that direction.
User avatar
severedskullz
Prole
Posts: 36
Joined: Thu May 30, 2013 1:55 am

Re: Tutorial on bullets?

Post by severedskullz »

I don't really have time to write a tutorial for you, but I hope these very helpful methods that I wrote in my own game will work for you.

Code: Select all

function dirVector(rot)
        --Returns the vector of the rotation in X and Y terms.
        -- Usually you use these as the update increments. Multiply them for faster traveling
	return math.cos(rot), math.sin(rot) 
end
function rotation(x1,y1, x2,y2)
        --Math.atan2 returns a radian between -Pi and Pi.
	return math.atan2(y2-y1, x2-x1) -- Return the rotation
end
Rotation will give you the rotation angle of 2 positions. X1 and Y1 are the starting positions and X2 and Y2 are the desired location. You can then pass in the rotation into dirVector which will return 2 variables: an X and Y position. You can use these in your update statements for your bullet entites. If it is too slow, and it most likely will be as these values range from 1, -1 then you may simply multiply the values returned by a constant to get faster speed.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Tutorial on bullets?

Post by micha »

I don't have a tutorial either, but I see two challenges in implementing bullets:
  • Creating a bullet that moves exactly in that direction that you want.
  • Creating and managing multiple bullets
Which of the two is difficult to get for you? Or is the problem even somewhere else?
User avatar
buhb11
Citizen
Posts: 81
Joined: Wed Dec 26, 2012 8:59 pm

Re: Tutorial on bullets?

Post by buhb11 »

Watch this vid : http://www.youtube.com/watch?v=S2oO2wbsXQs.If you got any questions ask me!
I found Love very enjoyable and nice!
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Tutorial on bullets?

Post by jjmafiae »

tuts?

you need to read some lua and experiment some more and then you will find it out :3

hint:
use tables!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests