random code

Posted By: Marwan

random code - 07/06/08 23:26

wussup george , I copied a randomization code from your aum from the questions section , i dont remember which one , and i modified it and made it like this

Code:
 function bat_direction()
{
       var index;
       index = random(10);
       var tempo = 0;
       while (index > 0)
       {	
               tempo = random (1);
               if (tempo <= 0.2)
               {
               my.pan+=0*time_step;
               }
               if ((tempo > 0.2) && (random(1)<= 0.4))
               {
                       my.pan+=10*time_step;
               }
               if ((tempo > 0.4) && (random(1) <= 0.6))
               {
                       my.pan-=10*time_step;
               }
               if ((tempo > 0.6) && (random(1)<= 0.8))
               {
                       my.tilt+=10*time_step;
               }
               if (tempo > 0.8)
               {
                       my.tilt-=10*time_step;
               }
               index-=1;
       }
}


it was for saving quotes in a random way , i only changed the instructions

the question is , whats the use of the index var , I replaced it with while loop , but it screwed it up

the other question is that i cant see any randomization , because i watched the pan variable of the entity and it only keeps increasing , it dont decrease at all , and vice versa with the tilt variable , it only keeps decreasing

and sorry for bothering you george

Posted By: George

Re: random code - 07/07/08 09:51

Don't worry, you don't bother me at all. What exactly are you trying to achieve?
Posted By: rvL_eXile

Re: random code - 07/07/08 18:22

I think hes confused about these Values (Pan/Tilt)... Add in the first line

Code:
my.pan%=360;
my.tilt%=360;


cYa Sebastian
Posted By: Marwan

Re: random code - 07/08/08 09:53

thanks george

I am trying to make some realistic movement for some flying bats , so I make them change their pan and tilt randomly and continously , as if they just flying around , and i made their moves look realistic , but i realized something wrong in their movement , so I watched the pan variable to see how does it change and i found it increasing only , it didnt decreasing even for a millisecond (assuming that the randomization changes every frame or sth like that ) so that means that there is no randomization at all
I closed the engine and ran it again a couple of times , but it gives the same result , i forgot to tell you that the same thing happens to the tilt value

I want to know why is that happening ?

and thanks again

ps :thanks sebastian but that wasnt exactly my point
Posted By: George

Re: random code - 07/10/08 19:30

I wrote some random bird flying code in one of the more recent magazines. Did you try it? Look for it in the "unanswered questions" (faq) section of the magazine.
Posted By: testDummy

Re: random code - 07/11/08 07:46

'I' would like a peek at that snippet, but there isn't time to look it up in an AUM index, at the moment.
Code:
// C-Script, 6.60
// use or ignore
// sample only
// untested
define _tm1, skill52;	// time counter for entity
define _dir1, skill53;  	// dir = 1,  or -1; pan
define _dir2, skill54;	// dir = 1, or -1 ; tilt

var mo = 0;		// time, time_step, synonym
var n1 = 0;		// temp var
var n2 = 0;		// temp var
var nStepPan = 5;	// step for pan
var nStepTilt = 5;	// step for tilt

function batty_f1() {
	timef();
	my.passable = ON;
	my._tm1 = max(my._tm1 - mo, 0);  // check that for inaccuracy
	if (my._tm1 <= 0.002) {
		my._tm1 = max(random(10), 1) * 16;
		if2(random(1) > 0.5, n1, 1, -1);
		if2(random(1) > 0.5, n2, 1, -1);
		my._dir1 = n1;
		my._dir2 = n2;
	}
	if (random(1) > 0.45) {
		my.pan += my._dir1 * nStepPan * mo;
		my.tilt += my._dir2 * nStepTilt * mo;
		my.tilt = clamp(my.tilt, -45, 45);
	}
	temp.x = 5 * mo;
	temp.y = 0;
	temp.z = 0;
	c_move(me, temp, nullvector, IGNORE_PASSABLE);
}
action batty_a1 {
	while(me != NULL) {
		batty_f1();
		wait(1);
	}
}


Tips hat at George.
'I' hope that 'you' are faring well.


Posted By: George

Re: random code - 07/11/08 10:38

Check out Aum45 to see an example.
Posted By: Marwan

Re: random code - 07/12/08 11:07

well , that should do it , but still one more something I need to know , How does the index var help , I saw it too in the script of the booker from the aum 72 code , nd its still confusing me , of course its not a predefined var , is it?
Posted By: George

Re: random code - 07/12/08 16:25

I have a hard time trying to debug other people's code; I have to get into their mindset in order to do that. "index" is just a regular name for a variable; I use it in loops or in repetitive actions and its value is usually incremented or decremented in a loop.
Posted By: Marwan

Re: random code - 07/12/08 21:04

thx again george
© 2024 lite-C Forums