# How to make a beam follow a path in xna

I'm making a 2D shmup with XNA 4.0 and one of the weapons in the game that I want is a laser beam that follows a path or a series of points and will smoothly beam along the path.

How would I go about achieving this?

• This is way too broad of a question. What do you have so far? Have you tried anything? Perhaps you have some code that isn't quite achieving the result you desire but almost?
– DomenicDatti
Commented May 29, 2012 at 15:55
• You've got to google around a bit and try it on your own first. SO is not in the business of hand-holding, sorry.
– SpikeX
Commented May 29, 2012 at 15:56
• Is gamedev.stackexchange.com/questions/29424/… what you're looking for? This question covers the 'bendy laser' that shows up in some shmups. Commented Jun 29, 2012 at 18:03

Try using a Queue of (x,y) coordinates. I don't know if you'll need to do it dynamically or at compile time, but you should be able to figure something out either way.

Are you wanting the laser to follow curves as well, or just connect the dots? If its the first option, you're gonna need to do some math too.

• Yes I want the laser to follow a curve. I have been playing around with some code and I can make lasers go in a straight line just fine so far.
– user1424132
Commented May 29, 2012 at 17:52
• And does it need to go exactly through every point, or would a best-fit curve work?
– Phillip Schmidt
Commented May 29, 2012 at 18:44
• Also, do we know anything about the nature of the curve? Is it going to depend on user input? I.e, is the equation of the curve going to be ever-changing? If so, you're fairly screwed here without some extremely complex math.
– Phillip Schmidt
Commented May 29, 2012 at 18:50
• no it doesn't have to go through every point. And I have never here of a best fit curve until now. But i'm assuming that it would take the shortest path from start to end.
– user1424132
Commented May 29, 2012 at 18:52
• Kind of. It's calculated using what called the 'least squares method'. An explanation of that method would be out of the scope of this answer, and it too requires some pretty high-level math (at least in nonlinear situations). Last question: where are you getting the points from? Do you have an equation for them, or are you just coming up with them yourself?
– Phillip Schmidt
Commented May 29, 2012 at 19:02