creating random numbers
Moderator: Moderators
creating random numbers
Hi guys i would like to know how to create random numbers. I placed a Zexpression on OnStart:a=random(25,25); and OnRender: Render a.Value. The variable a was placed in Content. However i keep getting the same number. It was 18, 25 or 0 depending on where i placed the ZExpression file, cuz i moved it all over to OnUpdate, OnRender, On Start. Please tell me how i could simplify this. The idea is that upon entering State, the random number will be generated and displayed on the screen. Thanks!
Hi zakkwylde,
Good for noticing this. If you have a application that requests a random number right at the start, you only get a random result when previewing your application in the Editor. For a standalone you need to set the random seed to something that varies each time .. time for example
Check this video for a demonstration.
@Ville - Would be handy if the seed was automatically set to Platform_GetTime ( ms being even better then sec ) or something at the start.
K
Good for noticing this. If you have a application that requests a random number right at the start, you only get a random result when previewing your application in the Editor. For a standalone you need to set the random seed to something that varies each time .. time for example

Check this video for a demonstration.
@Ville - Would be handy if the seed was automatically set to Platform_GetTime ( ms being even better then sec ) or something at the start.
K
Success!
Kjell, u hit it on the spot. I still do not get the link between random seed and random() but it worked like a charm. could you explain it in laymans terms?
oh and remember that walking animation you showed long ago? do you have the code for it? from ther ei could branch out to other actions like punch or kick or spin. Let me know, and thanks again for that simple solution, ur the best!!
oh and remember that walking animation you showed long ago? do you have the code for it? from ther ei could branch out to other actions like punch or kick or spin. Let me know, and thanks again for that simple solution, ur the best!!
Re: Success!
Hi zakkwylde,
K
Computers can't actually generate random numbers. Instead they use formula where one number is put in ( the seed ), and another comes out. So if you feed that formula the same number each time, the result will always be the same as well. That's why when you have a application that is basically a animation ( no keyboard / internet / clock input whatsoever ), the results of random() / rnd() will be the same each time you run it.zakkwylde wrote:Kjell, u hit it on the spot. I still do not get the link between random seed and random() but it worked like a charm. could you explain it in laymans terms?
You mean this? I wouldn't use that approach these days anymore ( back then there was no other option ). What kind of game are you trying to create?zakkwylde wrote:oh and remember that walking animation you showed long ago? do you have the code for it? from there i could branch out to other actions like punch or kick or spin.
K
random nos => animation
i'm trying to make an animal kaiser-ish kinda game. got tired of bringing my son to an arcade thats so far away so kinda wanted to make one that would keep him home. since the arcade machine needed players to put their cards in to scan it and choose the animal the player wants, i made it a random thing instead, which i may extend to being able to choose one day. The next is during the gameplay itself, the player presses a key which will generate a random 'attack' number. If this number is higher than the one generated for the opposing 'computer AI' player, then his animal executes an attack move which requires plenty of animation and particle effects. I'm working on the former first cuz i know i will be stumped by the latter. So just a simple movement of paws or a tail swipe would do. Any tips on that? Your walker animation would at least tell me how to join two different meshes and command them to move.
Re: random nos => animation
Hmm,

K
It really depends what techniques ( FK / morphing / skinned / procedural / baked / interpolated etc. ) you want to use. What application will you use to create the characters? Same question regarding the animations.zakkwylde wrote:So just a simple movement of paws or a tail swipe would do. Any tips on that?
Pretty sure I don't have the source of that example anymore, so I made it againzakkwylde wrote:Your walker animation would at least tell me how to join two different meshes and command them to move.

K
- Attachments
-
- Walkers.zgeproj
- (5.18 KiB) Downloaded 573 times
-
- Walkers.png (27.51 KiB) Viewed 15525 times
- jph_wacheski
- Posts: 1005
- Joined: Sat Feb 16, 2008 8:10 pm
- Location: Canada
- Contact:
"Would be handy if the seed was automatically set to Platform_GetTime ( ms being even better then sec ) or something at the start."
That would not be so good, I use the seeds to get the same results (with different seed values) some times as using the noise functions can be useful in generating complex data that is the same every time, i.e. level, tunes, etc.
It is simple enough to just call; setRandomSeed(getSystemTime()); on load if you want it randomized.
Kjell- that demo is quite cool, I particularly like the shadow technique!
That would not be so good, I use the seeds to get the same results (with different seed values) some times as using the noise functions can be useful in generating complex data that is the same every time, i.e. level, tunes, etc.
It is simple enough to just call; setRandomSeed(getSystemTime()); on load if you want it randomized.
Kjell- that demo is quite cool, I particularly like the shadow technique!
iterationGAMES.com
Hi jph,

K
Me too, more so then for getting different / random results. But setting the seed to something random-ish ( like the clock ) once at the start doesn't interfere with any setRandomSeed(9) calls. It is easy to fix manually indeed, but the fact that it's not consistent between the Editor and standalone-exe's right now catches people off-guard.jph_wacheski wrote:That would not be so good, I use the seeds to get the same results
I'd never use that technique in any actual projects thoughjph_wacheski wrote:that demo is quite cool, I particularly like the shadow technique!

K
I'm using Anim8or, and its not rated for animations, so i'm creating individual arm meshes and the intention is to join them up within ZGe itself. Hence the reason why the walker file would come useful. I have not opened it yet but if your walkers are able to move as a result of animation done within a 3D program itself then pls do share what program you are using. However i;m pretty confident that meshes cna be made to rotate within ZGE.
On another sidenote, i was pilfering thru the particles demo file packaged with ZGE and i'm still stumped. how on earth do i create a flame or a glow spot? The key component is the CursorModel..but i cant make any sense of it. Any help would be useful. But the random number's solved, damn good solve it was!
On another sidenote, i was pilfering thru the particles demo file packaged with ZGE and i'm still stumped. how on earth do i create a flame or a glow spot? The key component is the CursorModel..but i cant make any sense of it. Any help would be useful. But the random number's solved, damn good solve it was!
Hi zakkwylde,

K
Anim8tor actually does support all of the animation techniques i mentioned in my previous post. But separate meshes for limbs is definitely the easiest solution ( at the moment ).zakkwylde wrote:I'm using Anim8or, and its not rated for animations, so i'm creating individual arm meshes and the intention is to join them up within ZGe itself.
The example uses scripted animations, so yes .. you can do this within ZGEzakkwylde wrote:I have not opened it yet but if your walkers are able to move as a result of animation done within a 3D program itself then pls do share what program you are using. However i;m pretty confident that meshes cna be made to rotate within ZGE.

K
It's not that difficult, although I guess it would have helped if the particletoy project had any commentszakkwylde wrote:how on earth do i create a flame or a glow spot? The key component is the CursorModel..but i cant make any sense of it.

Everything is rendered with the RenderParticles-component. So examine how the scripting sets different property values on this component for different effects.
i got stuck at the animation part. Ok i got the meshes all ready and the one that i wanted to move was placed in rendertransform. Then i lifted the code off the FPSdemo of ZGE and made it rotate. worked but the rotation was off the CENTER of the mesh. i went back to Anim8or and moved the mesh off the center and redid it and it STILL rotated off the center! i;m at a loss, what can i do?
got it. I actually corrected this before when i discovered the auto centre by accident but not using it for awhile can make you forget. And the help file did not write anythin it about it either. But u guys solved it again. awesome! By the way is there any difference with AnimatorSimple and AnimatorGroup? If i want to make it so that the jaw of the animal shuts and then it rocks its head, i cant put it all in one animatorgroup component can i?