Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Getting the a straight line

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay here is what I have I have a square that is my ship. The ship can move anywhere around the screen and rotate. I want to produce a straight line of particles to be gun. I have been racking my head on this for a while trying to figure out how I can emit the particles from a particular corner in a straignt line. I tried doing the following: p3 p2 |----| | | |----| p1 p0 I want the particles to come out of p3 in a straight line so I figured if I just found the slop of p0 to p3. I could just use that as my scaleing factor for each of the particles. So I computed the xscaling and yscaling points as follows xscale = p3.x-p0.x; yscale = p3.y-p0.y; Then I run though a loop of like ten particles each time adding the previous location to the current location x =p3.x; y =p3.y; ---loop particle.x = x; particle.y = y; x += (xscale/40); y += (yscale/40); ---end loop This seemed to work pretty well but for some angles it just doesn't seem to work correcly the particles seem to come out a little off. Any advice is greatly appericated [edited by - l3arknight on February 19, 2004 9:16:51 PM] [edited by - l3arknight on February 19, 2004 9:18:38 PM]

Share this post

Link to post
Share on other sites
Well, each corner has an X and Y value, so you just compute rise over run.

If the particles need to be emitted from P3 then the equation is:
slope = (P3.Y-P0.Y)/(P3.X-P0.X)

Or, for particles coming out of P2:
slope = (P2.Y-P1.Y)/(P2.X-P1.X)

Then, for any particle that needs to travel on that line, you just increment X by 1 (or whatever value looks good) and compute Y like this:
Y = slope*X+OriginY

Where OriginY is the Y value of the corner that the particle started from.

[edited by - JNewt on February 19, 2004 9:31:33 PM]

Share this post

Link to post
Share on other sites
Oh, one thing I forgot: if the particle is emitted from either P3 or P1 (the left-side corners), X needs to be decremented each turn because you want the particles to move towards the left edge of the screen. With P2 and P0, X should be incremented.

Another thing that you can do for speed (though it's not a big deal) is precalculate the slope. If the rectangle's proportions remain the same throughout the game (you're not resizing it) then you can find the slope beforehand. Better yet, you only need to calculate one slope since the slope of the line through P3-P0 is just the negative of the slope of the line through P2-P1 and vice-versa.

[edited by - JNewt on February 20, 2004 11:09:46 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!