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

Started by
23 comments, last by mdias 9 years, 10 months ago
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
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Yes, what you describe is correct.
I am asking when to make a cargo truck arrive.
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.
void App::FrameUpdate() {
    int number = GetRandomNumber();
    if (number > 9000) { 
        arrive = true;
    }
}
Is or isn't this a good idea? Thanks Jack
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?

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

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.
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).

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

This topic is closed to new replies.

Advertisement