I'm creating a helicopter simulator (nothing huge, just for myself). I have some basic flight code down, but I want to have a ground effect simulation. Like when you're lower to the ground than the rotor's radius, then the blade efficiency increases.
Here's what I have so far, but I don't know how I would make the thrust variable actually
snap to twice its value, rather than exponentially increase.
Code:
#include <acknex.h> //pure mode
#include <default.c>
#include "vec_gfx.c" //vector graphics library
VECTOR* color= {x= 0; y= 0; z= 0;} //vector for line color
VECTOR* pos= {x= 512; y= 284;}
SOUND* heli= "heli_loop.wav";
float thrust,helihandle,eng_sound;
void _exit() //simple exit function (without #including default.c)
{
sys_exit(NULL);
}
void ground_effect()
{
while(1)
{
c_trace(me,vector(my.x,my.y,my.z - 0.5),IGNORE_ME | IGNORE_CONTENT);
if(trace_hit== 1)
{
thrust*= 1.01;
}
wait(1);
}
}
action phys_cam()
{
helihandle= snd_loop(heli,100,0);
eng_sound= 50;
//Setting up physics parameters:
ph_fps_max_lock= 75;
phent_settype (my,PH_RIGID,PH_BOX);
phent_setmass (my,10,PH_BOX);
phent_setfriction (my,10);
phent_setelasticity (my,10,10);
phent_setdamping (my,90,90);
ground_effect();
while(1) //This while loop enables user control:
{
eng_sound+= ((key_w * 2.5) - (key_s * 2.5)) * time_step;
snd_tune(helihandle,100,eng_sound,0);
phent_addtorquelocal (my,vector(0,15 * (mouse_force.y * time_step * -1),0));
phent_addtorquelocal (my,vector(0,0,15 * (mouse_force.x * time_step * -1)));
phent_addvellocal (my,vector(25 * (mouse_left * time_step - mouse_right * time_step),0,0),nullvector);
phent_addvellocal (my,vector(0,30 * (key_a * time_step - key_d * time_step),0),nullvector);
phent_addvellocal (my,vector(0,0,100 * (thrust * time_step)),nullvector);
thrust+= ((key_w * 0.03) - (key_s * 0.03)) * time_step;
if(mouse_middle== 1)
{
phent_addtorquelocal (my,vector(15 * (mouse_force.x * time_step),0,0));
}
camera.x= my.x; //Matching camera position and angle with physics object.
camera.y= my.y;
camera.z= my.z;
camera.pan= my.pan;
camera.tilt= my.tilt;
camera.roll= my.roll;
wait(1);
}
}
void main() //main() is always executed before every other piece of code.
{
video_mode= 8; //Set video parameters
video_screen= 1;
on_esc= _exit; //Executes exit function when we press Esc.
level_load("test.wmb"); //Load the level
wait(3);
ph_setgravity (vector(0,0,-980));
color.x= 0;
color.y= 255; //Sets the "color" vector to green.
color.z= 0;
ent_create("dummy.mdl",vector(200,0,100),phys_cam);
}
Also, I don't think c_trace is working correctly, because no matter what, it's always increasing (notice I set the trace distance to
0.5 quants away from the entity. That shouldn't even pass beyond the entity's bounding box!!).
