Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Need some help creating flight in an airplane game; Using vectors for realistic flight
Topic Started: Aug 5 2010, 12:30 PM (373 Views)
Harry
Newbie
[ * ]
Hi everyone,

Iam currently creating an online fighter airplane game simmilair to ace combat. However I have ran into a problem. I have absoloutley no Idea how to create realistic flight. I have done a search and found only one topic dating back to 2005, before U3D had the math functions. I have also done a search on the GMC and found a little tutorial on flight. However, it was written for the D3D functions and uses GML for the maths. I tried implementing into my game with no luck. However even if it did work it would be to slow. When I pressed two buttons at once the fps fell from 500 to 300! Iam assuming U3D would be alot faster.

Basically what happens at the moment is that when I press 'S' the rotx is decreased and the airplane goes upwards. However, obviously, when I press 'A' or 'D' and rotate the rotz of the plane, next time I press 'S' or 'W' the plane goes up or down. However it goes up or down as it did before. Completely ignoring the rotation of the airplane. I need the airplane to go up or down relative to the airplanes rotation, not relative to ground. I hope you understand what I mean.

I think what I need todo (after reading the D3D tutorial) is to create three vectors. One for x, one for y and one for z. I then need the vectors to rotate with the airplane and then somehow base the rotation or the movement of the airplane on the vectors? I find it all really confusing. I have ready the manual twice but I still don't even know how to use vectors (or matrices/matrix's?, I think you have to use both?).

Hopefully this should be fairly easy for someone who knows about these things to tell me how to do it. In the topic dating back to 2005 I believe Dr. Best said that if there where Math functions in U3D it would be very easy to do. Instead he wrote an entire script in GML to make it work. By the way I did try that script a few months ago but couldn't get that to work either..


By the way here is a screenshot of my game so far. It is about 90% complete now. The online is now complete so there isnt much left todo. All I need todo is make it so that people can shoot eachother down, add some sort of unique gameplay to it (Just shooting eachother down could get boring after a while) and make the flying realistic! Now I have finished colledge Iam working on it 10-12 hours a day so it will be finished next week, I will upload it once I have created a website. :yahoo:

Posted Image
Offline Profile Quote Post Goto Top
 
Eansis
Member Avatar
ghost
[ *  *  *  *  *  * ]
EDIT: Crap the download expired...anyone have this on their computer?

made an example:

There is only one bug, You can use a joystick, but if you unplug it you will get lag. So make sure you really want to use a joystick because you cannot unplug it (without restarting your computer.)
http://filebeam.com/0be5711312d2ac17e809a755d32d3ff9

It is not 100% realistic but it should be good enough to start.

Helpful Description of keys and meanings

-AGL > How high the plane is. If this is at 1 or 0 that means you're still on the ground.

-THR > Throttle (In %. AB = Afterburn, > 100%.)

-AOA > Angle of Attack (Currently displays incorrect values).

-VEL > Airspeed (In knots).

-SB > Speedbrake (Slows aircraft down). Keypress "B".

-WB > Wheelbrake (Slows aircraft down, only when on ground). More effective than Speedbrake. Keypress "W".

-Rudder > Yaws aircraft left and right. Keypress "Z" and "C". Joystick buttons "3" and "4".

-Elevator > Pitches aircraft up and down. Keypress "Up arrow and Down arrow". Joystick Axis 1.

-Ailerons > Rolls aircraft left and right. Keypress "Left arrow" and "Right arrow". Joystick Axis 1.
Edited by Eansis, Aug 5 2010, 04:07 PM.
VOTE FOR BUDDY ROEMER HE'S A STRAIGHTFORWARD, DOWN TO EARTH AMERICAN GUY WHO ISN'T PART OF THE BIGBROTHER CONSPIRACY

Til'c
 
Things will not calm down Daniel Jackson. They will infact calm up.
Offline Profile Quote Post Goto Top
 
Sothh
Member Avatar
Shaman Of Time
[ *  *  *  *  *  * ]
Since MisteriXYZ is not here I will have to answer...

What you need is matrix'es!

Heres what you need:

Code:
 
var PitchOffset,YawOffset,RollOffset;

//set the local rotation offsets of the plane, based on user input
PitchOffset=(speed2 * .5)*Pitch;
if (rotz > 0) {if (rotz < 180) then {if (rotz < 90) then YawOffset-=.005*rotz else YawOffset-=.005*(180-rotz)}};
if (rotz < 0) {if (rotz > -180) then {if (rotz > -90) then YawOffset-=.005*rotz else YawOffset-=.005*(-180-rotz)}};
RollOffset=(speed2 * 1)*Roll;

var PlaneToWorld,RotToPlane,RotToWorld;

//"rotation-to-plane" (for pitch)
RotToPlane=CreateRotationMatrix(-1,PitchOffset,0,0);
//"plane-to-world"
PlaneToWorld=GetObjectTransformation(id);
//"rotation-to-world" = rotation-to-plane * plane-to-world
RotToWorld=TransformMatrix(-1,RotToPlane,PlaneToWorld);

//"rotation-to-plane" (for roll)
CreateRotationMatrix(RotToPlane,0,0,RollOffset);
//the old "rotation-to-world" is actually the new "plane-to-world";
//"rotation-to-world" = rotation-to-plane * plane-to-world
TransformMatrix(RotToWorld,RotToPlane,RotToWorld);

var AngleVect,YawToWorld;

//get the angles that make up the plane's current orientation...
AngleVect=ComputeMatrixRotationAngles(-1,RotToWorld);
//...and turn them into a matrix
CreateRotationMatrix
(
RotToWorld,
GetVector(AngleVect,1),
GetVector(AngleVect,2),
GetVector(AngleVect,3),
);

//define the matrix decribing the yaw offset...
YawToWorld=CreateRotationMatrix(-1,0,YawOffset,0);
//...and transform the previous matrix with it
TransformMatrix(RotToWorld,RotToWorld,YawToWorld);

//finally, retrieve the angles that make up the plane's new orientation...
ComputeMatrixRotationAngles(AngleVect,RotToWorld);
//...and assign them to the plane's rotx/y/z
rotx=GetVector(AngleVect,1);
roty=GetVector(AngleVect,2);
rotz=GetVector(AngleVect,3);

ReleaseVector(AngleVect);
ReleaseMatrix(PlaneToWorld);
ReleaseMatrix(RotToPlane);
ReleaseMatrix(RotToWorld);
ReleaseMatrix(YawToWorld);

//Move Plane
Move(rotx,roty,speed2*2.5);
//Set Falling Speed
falling_speed=(-1 + speed2)*25;
//Set speed2 to Absolut 0
if speed2 < .01 then speed2=.0;
//Set AOA
if (AOA>rotx) then AOA-=.5;
if (AOA<rotx) then AOA+=.5;
//Set speed
speed2=speed1 + AOA * .05;
if speed1 > Thrust then speed1-=.01;
if speed1 < Thrust then speed1+=.05;

//Keyboard stuff
if (keyboard_check(vk_up)=1) then {if (Pitch<1) then Pitch+=.25}
if (keyboard_check(vk_down)=1) then {if (Pitch>-1) then Pitch-=.25}
if (!keyboard_check(vk_up)=1) && (!keyboard_check(vk_down)=1) then {if (Pitch>0) then Pitch-=.25; if (Pitch<0) then Pitch+=.25;}

if (keyboard_check(vk_left)=1) then {if (Roll<1) then Roll+=.25}
if (keyboard_check(vk_right)=1) then {if (Roll>-1) then Roll-=.25}
if (!keyboard_check(vk_left)=1) && (!keyboard_check(vk_right)=1) then {if (Roll>0) then Roll-=.25; if (Roll<0) then Roll+=.25;}
//Joystick stuff
if (options.useJoystick=1) then
{
if joystick_exists(1) then
{
Roll=-joystick_xpos(1);
Pitch=-joystick_ypos(1);
Joy_Z=joystick_zpos(1)*-5+5;
Thrust=Joy_Z/2;
}
}
//Mouse stuff
if (options.useMouse=1) then
{
GetMousePos();
Pitch-=(global.mouse_y-display_get_height()/2)/1000;
Roll-=(global.mouse_x-display_get_width()/2)/1000;
}

if (Pitch>1) then Pitch=1;
if (Pitch<-1) then Pitch=-1;
if (Roll>1) then Roll=1;
if (Roll<-1) then Roll=-1;


Thats the step event of an old flight simulator I made. Simply set the Thrust var and your ready to go.

You won't need that much code, but I included my physics.
“You can’t outrun Death forever.
But you can make the Bastard work for it.”

Major Korgo Korgar
“Last of The Lancers” - AFC 32
(Andromeda Ascendant Record Database)
Offline Profile Quote Post Goto Top
 
Harry
Newbie
[ * ]
Thanks it works great! :clapping: haha also I now have it so that it speeds up going downhill and slows down going up! well, thats the hard stuff done now (online and flight eninge), Iam now set and ready for a finishing date of wednesday :yahoo:
Offline Profile Quote Post Goto Top
 
Sothh
Member Avatar
Shaman Of Time
[ *  *  *  *  *  * ]
Thanks! And remember to give credit where credit is due. ;)

I can't wait to see it!

If you have any more questions feel free to pm me.

By the way, as you should see you can enable joystick and mouse control as well. You might want to add a option in the game to do this.
“You can’t outrun Death forever.
But you can make the Bastard work for it.”

Major Korgo Korgar
“Last of The Lancers” - AFC 32
(Andromeda Ascendant Record Database)
Offline Profile Quote Post Goto Top
 
mardyart
Advanced Member
[ *  *  * ]
How could I modify this to work on a planet model where it rotates at a constant rate around the roty(yaw) axis but has a fixed tilt of 23.5 deg on the rotx(pitch) axis. Any help would be appreciated.
There are 10 kinds of people in the world: Those who understand binary and those who don't.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply