Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
24 replies to this topic

#1   Members   

1183
Like
0Likes
Like

Posted 04 June 2014 - 11:48 PM

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

#2   Members   

24827
Like
0Likes
Like

Posted 04 June 2014 - 11:56 PM

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, 06 June 2014 - 02:44 AM.


#3   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 12:03 AM

Yes, what you describe is correct.
I am asking when to make a cargo truck arrive.

#4   Members   

8647
Like
0Likes
Like

Posted 05 June 2014 - 01:50 AM

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.

#5   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 02:19 AM

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

#6   Members   

8647
Like
0Likes
Like

Posted 05 June 2014 - 04:04 AM

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?

#7   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 04:17 AM

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



#8   Members   

8647
Like
0Likes
Like

Posted 05 June 2014 - 04:27 AM

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.

#9   Members   

20255
Like
0Likes
Like

Posted 05 June 2014 - 04:44 AM

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

#10   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 05:52 AM

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, 05 June 2014 - 05:54 AM.


#11   Members   

4090
Like
0Likes
Like

Posted 05 June 2014 - 05:59 AM

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?



#12   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 06:21 AM

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, 05 June 2014 - 06:28 AM.


#13   Members   

4090
Like
0Likes
Like

Posted 05 June 2014 - 06:51 AM

I dont understand this list.

 

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



#14   Members   

1183
Like
0Likes
Like

Posted 05 June 2014 - 07:20 AM

You may think of it as if there is some deviation based on this data.

Thanks

Jack



#15   Members   

4090
Like
6Likes
Like

Posted 05 June 2014 - 07:33 AM

*
POPULAR

so you have a list of trucks that arrive after a specified amount of minutes plus or minus a random amount of minutes. And you want to take the next truck out of this list when the amount of minutes has passed.

 

Is this correct?



#16   Members   

1183
Like
-1Likes
Like

Posted 05 June 2014 - 10:52 PM

Yes, and it would be perfectly nice to post some example code for me.

Thanks

Jack


Edited by lucky6969b, 05 June 2014 - 10:58 PM.


#17   Members   

4090
Like
0Likes
Like

Posted 06 June 2014 - 02:26 AM

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.



#18   Members   

2055
Like
0Likes
Like

Posted 06 June 2014 - 03:24 AM

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, 06 June 2014 - 03:26 AM.


#19   Members   

5832
Like
0Likes
Like

Posted 06 June 2014 - 04:38 AM

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


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#20   Members   

1183
Like
0Likes
Like

Posted 06 June 2014 - 04:45 AM

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, 06 June 2014 - 04:52 AM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.