• Advertisement
Sign in to follow this  

[updated]: Make certain objects arrive in the scene (a lorry)

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

I think I've asked this question before, but I've lost the link to that post.
I wonder what is the best way to make a lorry arrives.
I remember somebody told me that keeping a series of random numbers and
choose one of them, and see if that number is larger than a certain threshold,
then a lorry will arrive is not a good idea.
Could anyone please refresh my memory? I forgot what that post says.
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement
I don’t have time to answer; I only have time to clarify what he is trying to ask for those who were just as confused as I originally was the first 10 times I re-read it.
 
He is asking when to make a cargo truck arrive.
The procedure for deciding when to make the truck appear at a certain place.
 
Not for detecting when it arrives at a certain place.
 
 
L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
There is no right answer for this. You might want it to arrive when the player did X (whether that's entering an area for the first time or completing a quest). You might want to roll a random number every X time units and if the result fulfills a criteria you make it arrive. You might want to connect to a central server and that decides when it's lorry time for every player in the world.

All of these are reasonable for certain design decisions. Many more are possible.

Share this post


Link to post
Share on other sites
void App::FrameUpdate() {
    int number = GetRandomNumber();
    if (number > 9000) { 
        arrive = true;
    }
}
Is or isn't this a good idea? Thanks Jack

Share this post


Link to post
Share on other sites
How frequently is the function run? What range of values does GetRandomNumber return? What is the resulting expected arrival time calculated from those two values?

Share this post


Link to post
Share on other sites

Hello BitMaster,

Thanks for helping.

I am not sure how to tell how frequently the function runs. I am using the Ogre3D rendering engine.

Is there a way to measure this frequency? The numbers that return will be in the range of 1-10000

so there will be 90% of the chance that the lorry will not appear?

Thanks

Jack

Share this post


Link to post
Share on other sites
Assuming the function is run 25 times per second (not unreasonable for an update function) the probability for the lorry not having arrived after 1 second is 0.1^25 = 0,0000000000000000000000001. For all practical purposes, the lorry will always be there 1 second after you started.

Share this post


Link to post
Share on other sites
Related to BitMaster's computation, if the lorry has probability p of arriving each frame, in the average you'll have to wait 1/p frames for it to arrive (so 10 frames in your example, which at 25 frames per second would be 0.4 seconds).

Share this post


Link to post
Share on other sites

If I want to make this more deterministic (but still more or less random) as I need to load some data from Excel

that determines how the program would behave...

pretty stumped now. What are your suggestions to me?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

We need more info...

 

What is the intended behaviour?

Should the lorry appear once every x seconds?

Once the level starts?

After a random amount of time?

Share this post


Link to post
Share on other sites
Date              Time       Apple    Orange   Pear
10/10/2009        7:00       1
                  8:00       1                 1

The Date and time are the "Cartons or pallets" arrival dates and times, they arrive in the trailer of the truck

I need to convert this data into the probability of truck arrival time....

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

I dont understand this list.

 

Doesn't it mean that the truck will always arrive at a specified time? If so, why the randomness?

Share this post


Link to post
Share on other sites

Come on... I'm not going to write the code for you. My last post should have all the info you need to implement something that you can build upon.

Share this post


Link to post
Share on other sites
Keep in mind that "random" isn't necessarily random in the way it sounds.

I.e. if you're going to add/subtract a random amount of time to when a truck arrives you'll want to determine a threshold, what is the maximum amount of time the truck could be early/late. for instance if the truck arrived at 1:00 you could set a 20 minute threshold for both arriving late or arriving early.

After that it kinda depends on the math you want to use, you could use a rand function between -20 and 20 and apply the difference(that may require a little fiddling if you're using an object representing time with a unique type) or you could pick a random 0-20 and then decide to add or subtract based on a second rand roll.

Anyway the math doesn't matter that much, the point is more that in terms of computers you're almost never going to just pick some totally random number. Most of what everyone has been trying to convey to you so far in the thread is that you have to look at your problem and decide how best to tackle it for your unique situation. Edited by Satharis

Share this post


Link to post
Share on other sites

If you want to model number of arrivals in a discrete time period (e.g. number of arrivals per hour, with some mean number of arrivals per time unit), you want to use the Poisson distribution:

 

http://en.wikipedia.org/wiki/Poisson_distribution

 

If you just want to model time between arrivals (with a certain mean time of arrival) you want the exponential distribution:

 

http://en.wikipedia.org/wiki/Exponential_distribution

Share this post


Link to post
Share on other sites

Okay, I'll think thru it, and see I can come up with a solution.

Sorry, I was too impulsive to ask for an instant answer....

Thanks everybody

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

It's a C++ library which encompasses all the features we discussed above.

I found one of them on my hard drive, which is called C++ Sim,

But I think I have to give it up, because it is written for unix, not win32

which is the platform I am currently working on.

Sorry, I forgot to link to share. But it's from the University of NewCastle, UK

Edited by lucky6969b

Share this post


Link to post
Share on other sites
There are plenty of timer examples out there. All you need is to decide on a "normal" time each truck arrives and add/subtract some random value from the time. When that time is reached in your game loop, send in the truck (lorry). You don't need to make this any more complicated with simulation libraries.....

Share this post


Link to post
Share on other sites

Wouldn't it just be easier to, at load time of the data you have, add/subtract a random number so that at load time you already have "randomized" data and act deterministically from there?

 

If you want to repeat the process several times, keep a copy of the original data, and recalculate the next time (with some randomness) a truck should go everytime a new truck goes.

Edited by mdias

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement