creating random numbers

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

creating random numbers

Post by zakkwylde »

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!
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

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
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Success!

Post by zakkwylde »

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!!
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Re: Success!

Post by Kjell »

Hi zakkwylde,
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?
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: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.
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?

K
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

random nos => animation

Post by zakkwylde »

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.
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Re: random nos => animation

Post by Kjell »

Hmm,
zakkwylde wrote:So just a simple movement of paws or a tail swipe would do. Any tips on that?
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:Your walker animation would at least tell me how to join two different meshes and command them to move.
Pretty sure I don't have the source of that example anymore, so I made it again :)

K
Attachments
Walkers.zgeproj
(5.18 KiB) Downloaded 574 times
Walkers.png
Walkers.png (27.51 KiB) Viewed 15527 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

"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!
iterationGAMES.com
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,
jph_wacheski wrote:That would not be so good, I use the seeds to get the same results
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 demo is quite cool, I particularly like the shadow technique!
I'd never use that technique in any actual projects though :P

K
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Post by zakkwylde »

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!
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi zakkwylde,
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.
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 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.
The example uses scripted animations, so yes .. you can do this within ZGE :)

K
User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

zakkwylde 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.
It's not that difficult, although I guess it would have helped if the particletoy project had any comments :)
Everything is rendered with the RenderParticles-component. So examine how the scripting sets different property values on this component for different effects.
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Post by zakkwylde »

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?
User avatar
VilleK
Site Admin
Posts: 2382
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Make sure you uncheck "auto-center mesh" when importing 3ds-file to keep the original position. If you still can't get it to work try posting the 3ds-file here so that we can take a look at it.
User avatar
Kjell
Posts: 1929
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

...

@Ville - Told you :wink:

@zakkwylde - It's a ( ancient ) bug in the importer. The only way to go around it is to unparent your individual body parts and position them all at 0,0,0 in the world before exporting. Very inconvenient .. and hopefully it will be fixed soon.

K
User avatar
zakkwylde
Posts: 29
Joined: Sun Feb 24, 2008 1:38 am
Location: France

Post by zakkwylde »

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?
Post Reply