Jump to content
  • Advertisement


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


Character motion paths

This topic is 6917 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

Can anyone suggest ways in which I can get my NPCs to move around the map in specific paths. Ideally, I would like my characters to have a few possible paths to choose from depending on what other characters are doing. My problem is I really don''t know how to go about writing code to set up such a system. Are there any tutorials or articles around that I can refer to? I have set up my scrolling map and got my player character working and moving beautifully and also I am displaying my NPC properly with correct animations but I am stubbing my toe on how to implement their motion paths. Any help will be greatly appreciated. Thanks

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
What you need is just a list of coordinates like: (5, 5), (10, 5), (10, 10), (5, 10)
Store them in a file (Probably I set per line) and read the coordinates into an array.
Move 1 step closer to the first point by checking whether the characters xy coordinates are greater or less than the target (the point).
Then, if the character is on the point, start moving to the next point.

You may want to store more than just coordinates in the file, maybe a simple code so:
0 = MoveTo
1 = Say
2 = Wait

Then have something like
0, 5, 5
0, 10, 5
1, "Nice day"
2, 5
0, 10, 10

Hope this helps

Share this post

Link to post
Share on other sites
okay, first off, if you''re just gonna walk in a straight line between waypoints, use a real line algorithm. second, what exactly are you planning on doing when you run into the first tree?
and what if the characters are actually supposed to do something based on the circumstances (that little thing known as AI)?

Float like a butterfly, bite like a crocodile.

Share this post

Link to post
Share on other sites
Thanks for your posts. Here''s an example of what I''m hoping to get a particular character to do. Start at position A and head straight for position B, once there pick up object and return to position B. If character 2 is within range at anytime head for character 2 and attempt to engage. If succesful head for Position A again. This is just an example.
I''m going to try and set something up along the lines of the suggestions you have made.

Share this post

Link to post
Share on other sites
I think the best thing for that would be a FSM (finite state machine) for your AI. In case you aren''t familiar with this I will give a brief explaination.

First, you define a set of states for your NPC. In your example you might have 4 states (A, B, C, D) In state A, your character is walking to location A. In state B, he is walking to location B. In state C, he is walking to engage charater 2. And in state D he is actually engaging character 2.

Next, you set up a serise of transitions between the states and conditions when these transitions should occur. From state A, you would want to keep walking if you are not at A. If you are at A, then you would want to transition to state B (walking to location B.) From state B, you would transition to state A if you had reached location B. If player 2 was within a specified range, you would transition to state C and in any other case, you would keep walking toward B (remaining in state B.)

You can probably figure out the rest of the details and decide when you need more states or transitions, etc. Basically, though, each update you check the state of the character and then check any conditions that can lead to state changes from the current state (and change state if needed.) Then, you have the character perform an action based on its current state.

Hope that helps, if you need more info, drop me an email (cbradford@hmc.edu)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!