3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Help with the script  (Read 646 times)

« on: March 24, 2012, 11:14:32 AM »
Hello,

I am trying to do a project of a remote controlled aeroplane that flyes from island 'A' to 'B' automatically with the help of the user...

I am currently at the beginning of the project and right now, and what I did was get the AircraftDemo_autobalance.3dr project and changed the script a little in the 'thrust script' making the aircraft Bank left, right, turn left and right and go up and down without the help of the user (the project ---> aircraft_change_2.3dr)

now I am trying to the same thing but with different scripts, i.e: a script for the thrust (where it will start after a timer reaches 20) and a script for the elevation where when the thrust reaches a certain value elevation angle control is 1, and after a period of 600 cycles the aircraft's elevation angle control will change according to a random number (Random). When Random = 0,1,2  angle control will be -1,0,1 respectively. (the project ---> UAV_online.3dr)

Script for Thrust
Quote
//Intercept thrust control keypresses and
//set propeller force intensity accordingly
float TargetThrust = 0;
float Thrust = 0;

int Timer = 0;

void Main()
{
   if (iInitializing())
   {
      Timer = 0;
      TargetThrust = 0; //reset
   }
   //set TargetThrust value depending on what key is pressed

   TargetThrust = 10000;

   if (Timer >= 20) TargetThrust = 20000;
   
   Thrust = iFloatTendTo(Thrust,0,TargetThrust,0.01,0);
   //set propeller force intensity
   OUT_0 = Thrust;
   //set the value to print (engine %)
   OUT_9 = Thrust;

   //print the timers value

   OUT_18 = Timer;
   
   OUT_40 = OUT_0; //VAL_1 is the force propeller
   OUT_41 = Timer; //VAL_2 is the timer
   
   Timer++;

   
}

Script for Elevation
Quote
float Elevation = 0;
float TargetElevation = 0;

float Random = 0;

int VAL_timer_0 = 0;
int VAL_timer_1 = 0;

int i = 0;

void Main()
{
   if (iInitializing());

   VAL_timer_0 = VAL_2;

   if(i == 150)
   {
      Random = iFloatRand(0,2);
      i = 0;
   }

   //if thrust = 20000 lift

   if(VAL_1 >= 20000 && VAL_2 < 600) TargetElevation = 1;

   else if(VAL_1 >= 20000 && VAL_2 >= 600) //val2 is timer
   {
      if(Random == 0 && VAL_2 >= 1000) TargetElevation = -1;

      else if (Random == 1 && VAL_2 >= 1600) TargetElevation = 0;

      else if (Random == 2 && VAL_2 >= 2000) TargetElevation = 1;
   }

   Elevation = iFloatTendTo(Elevation,0,TargetElevation,0.01,0);

   OUT_44 = Elevation;

   OUT_88 = Random;

   OUT_110 = Elevation;

   OUT_132 = i;
 
   i++;
}

Now the problem is that after Timer >= 600, the TargetElevation and Elevation seems to be stuck in 1 and it doesnt change, I tried to remove the Random number generator (iFloatRand()) and made it sequential (i increments every cycle and if even change TE and if odd change it to something else) but that didnt work, then I tried to add another Timer that goes to 150 before generating a random number and storing it in Random, still no result.

Can someone with a bit more experience than me help me out with this problem.

(PS I added the project just if someone needed to have a look at the projects)

Regards,
Forat
« Reply #1 on: March 28, 2012, 08:24:15 PM »
sounds like an interesting project... but this question really should be in one of the other forums (tech)...

--Mike




RRSoft

« Reply #2 on: March 29, 2012, 11:45:00 AM »
[]
« Last Edit: March 30, 2012, 08:54:12 PM by RRSoft »
Pages: [1]