Closed Thread
Results 1 to 6 of 6

Thread: Creating a Path

  1. #1
    Senior Member
    Join Date
    Sep 2005
    Location
    Ohio, USA
    Posts
    712

    Question Creating a Path

    How do you create a destined path for an object to follow?

    If I were to draw by freehand a path, how would I get an object to follow that exact path?

    Seeing as how I can think of many ways it could be done, what do you think would be most efficient?

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Location
    BC, Canada
    Posts
    357

    Default

    A lot of developers I know take advantage of bezier curves. Just plot a few points and you get some perfectly smooth paths I've never used them myself, but I would recommend looking into them.

    There are probably a million other ways to do it (depending on what you need the paths for)
    Nathaniel Sabanski
    http://www.Geenat.com - Gnat's Design and Development Blog | http://www.NConsulting.ca - Website Production Services

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Location
    San Mateo, CA
    Posts
    359

    Default

    Ignoring timing, the simplist method is just to digitize a bunch
    of points along the path and store them in a list.
    (0,0)
    (1,4)
    (2,5)
    ...
    But digitizing is a pain. So the next simplest is to use linear interpolation.
    Digitize the ends of straight lines and use this equation to move between
    the points:

    p = p0 + fract*(p1-p0)

    But you have to digitize alot of straight segments to approximate a curve,
    so you could use some sort of spline function. One of the most simple is the
    Hermite cubic spline. To use it you need two end points p0, p1 and two
    tangents at the end points tan0, tan1

    p = A + B*fract + C*fract*fract + D*fract*fract*fract
    where
    A = p0
    B = tan0
    C = 3*(p1-p0) - 2*tan0 - p0
    D = 2*(p0-p1) + tan0 + tan1

    Using this spline, all you have to digitize is a small number of key points
    and the tangents at these points. There are methods to compute those
    tangents.

    Hope this helps....

  4. #4
    Administrator
    Join Date
    Jul 2004
    Posts
    3,401

    Default

    One way I've done it is record a macro in a paint program as I lay down points using a line drawing tool. Then I take the macro and edit out the points from it to create the data file. Then I load the points into my game and interpolate through them creating an array of equidistant points for an object to follow.

    - S
    Steve Verreault - Twilight Games
    http://www.twilightgames.com --- http://www.indiegamer.com

    "Do you really think it is weakness that yields to temptation? I tell you that there are terrible temptations which it requires strength, strength and courage to yield to.” - Oscar Wilde

  5. #5
    Moderator
    Join Date
    Jul 2004
    Location
    Zürich, Switzerland
    Posts
    1,966

    Default

    From the FAQ :
    1. Do not post requests for [...] help with your code or how to code it - These subjects are well covered by other forums such as Gamedev.net and Ludumdare.
    Gabriel Gambetta
    Google Zürich - Formerly Mystery Studio

  6. #6
    Administrator
    Join Date
    Jul 2004
    Posts
    3,401

    Default

    I think I might actually be inclined to change up that faq a little.. seems like a reasonable place to post this kind of question. I guess the fear is that we're going to end up with a ton of specific basic coding questions, which really would be better handled on another site. But I quite like the detailed technical discussion of how to implement things like paths, dirty rects etc... specific to game development.
    Steve Verreault - Twilight Games
    http://www.twilightgames.com --- http://www.indiegamer.com

    "Do you really think it is weakness that yields to temptation? I tell you that there are terrible temptations which it requires strength, strength and courage to yield to.” - Oscar Wilde

Closed Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts