Advertisement

Random wandering trouble with multiple entities

Started by March 26, 2009 07:04 AM
1 comment, last by Morrandir 15 years, 8 months ago
Hey, I'm busy making a wandering path for my entities in our engine, but i'm a bit stuck at some point. I have an entity that moves from his starting vector to another random generated vector based on his starting vector and a randomized int. this works perfectly but the thing is, when i put another entity on it, it will (logically) move in exact the same way. so i was wondering if any of you guys could give me some tips on how to get 2 (and more) entities to have a seperate randomized vector based on something unique of that entity. something like the addres of an entity, but i don't know how (and if it's even able) to convert something like that to an int. thanks in advance.
I *think* many random number generator functions will give you the same "randomly" generated numbers in the same sequence.

There is probably a way you can alter them by using a player ID in some way etc.
Another way would be for all your players to use the SAME instance of the random generator function, as opposed to different instances of the same function. If you use different instances they will return the same sequences, if you use the same instance for all of them, they will each take a different part of that sequence and return different results.

Just a guess.
Advertisement
Do you want a randomized vector based on some entity property or just any randomized vector which is different for every entity?

In case #2, just make a global random generator (details depend on your programming language), and extract subsequent values from it for your entities.

Note that many random generators require a seed to generate their random sequences. People usually use current time as a seed, and a very common mistake beginners make is seeding the generator again before each use. This usually results in seeding with the same time, leading to the same random sequence and getting the same 'random' values with each use. Make sure you seed your random generator only once before the first use, for example at the beginning of your program.

This topic is closed to new replies.

Advertisement