Skip to main content
gamedev.net
🔒 Locked

Wander

Started by cpp boy 3 replies 650+ views
Original Post
cpp boy
cpp boy
I was wondering how to do wander like they do in rpg. It ceartenly more than a random because when i do random the personne is shaking and making the shajke shake shake dance like in the simpsons. So what is the algorymthe or a c++ code to do soo Kevin
Kevin
vtwin
vtwin
...Uh, yeah..

Don''t make every single movement random, that will just cause the character to "shake around", as you call it. Instead, set random waypoints for the unit to move to. Every time the unit moves to the waypoint, set another one at a random location.


swift URL | browse my bookmarks [server may not always be on]

Sensimed | Info/download
Hollower
Hollower
You can also set a maximum amount they are allowed to turn from the current rotation to keep ''em from zigging too much.
llama_beast
llama_beast
direction = rand()%8; //varies according to game type
time = (rand()%50000)+1000; //numbers vary greatly

while(--time)
{
move(direction);
}


If barbie is so popular, why do you have to buy her friends?
If barbie is so popular, why do you have to buy her friends?
Kylotan
Kylotan
My MUD uses a simple depth-first ''search'' for wandering. Pick a direction, then pick a direction from wherever that last one would take you, and repeat until you''ve moved far enough from the original position. Then you have a path for the character to follow.

For a game with more logical topology (eg. RPG/RTS/FPS/etc), you may want to pick a position on the map/level at random - perhaps within a certain maximum distance of the current position - and plot a path (using breadth-first search, or A*, etc) there.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.