Sign in to follow this  
DriveByBaptism

Sprite Path Finding

Recommended Posts

DriveByBaptism    122
Morning At the moment I'm making a platformer. I've managed to get my levels loading in from text files (thanks guys) but what I want is to have certain sprites/platforms follow a pre-defined path. I've tried googleing some tutorials but can't find anything. Is there anyway I can use this using lists or something. I just want really basic AI(no A* path finding for example) to do this with and don't want to hard code in all the locations? Any help would be great.

Share this post


Link to post
Share on other sites
Evil Steve    2017
[Moving to Game Programming; not DirectX related]

You could store the path for the sprites to move along as a list of points, and then have each sprites progress as a float between 0 and list.size(), where 0 is at the first point, 0.5 is halfway between the first and second point, etc.

Then, moving them becomes a case of increasing the progress by their speed (Possibly biased by the distance between the previous and next points to keep the speed constant where the distance between points isn't), and drawing the sprite at a position lerped from the previous and next points.

Share this post


Link to post
Share on other sites
bzroom    647
Path following and path finding are two very different things. It is possible though, with a generic enough path following algorithm, to "find" a path.

Path following means you know the path, you just need to get your self onto and along it.

Path finding means you have no idea where to go, and you need to search until you do.

A* would be path finding. Interpolation as described above would be path following.

The following techniques are path following, but because they're so generic, can be used to find a path also.
Click-> http://www.red3d.com/cwr/steer/

Share this post


Link to post
Share on other sites
Captain P    1092
Quote:
Original post by DriveByBaptism
I've tried googleing some tutorials but can't find anything. Is there anyway I can use this using lists or something. I just want really basic AI(no A* path finding for example) to do this with and don't want to hard code in all the locations

Since you're storing level-data in files now anyway, why not store these paths in those files as well? One way would be to store named path-node objects, that reference a next path-node by it's name. Other game objects can then do the same: they simply need the name of the first path-node to travel to, and once they've arrived, they can check what path-node is next.

Of course, once you've loaded these path-node objects from the level file, you could give each path-node a reference (pointer) to it's next path-node, for faster lookup.

Share this post


Link to post
Share on other sites
DriveByBaptism    122
Hi guys thanks for the replys.

I should have said that I'm doing this in C# using XNA, hence why it was in the directx/xna section (sorry for not being more clear).

I will have a look at these links and such in more detail. :)

Share this post


Link to post
Share on other sites
LionMX    100
This is not a c# or XNA specific problem ;-)

A good book worth a read is AI for Game Developers by David M. Bourg, Glenn Seeman. In Chapter 6 it discusses path following, it is a very easy book to read and even provides demo's. I think it would help you a lot with this problem.

Share this post


Link to post
Share on other sites
theOcelot    498
You could also store the path as movement directions: move up for 10 pixels, move diagonally down and to the right for 30 pixels, etc. You could include speed in the mix, or measure directions by angles.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this