Flight Controls

Hello. I am creating a aircraft racing game (Hover Craft) but cannot get the controls right. I want to be able to use a joystick (xbox 360) and use the left analog to steer and the right analog to control the camera.

The thing is that I cannot get the plane to even fly. I have tried playing with constant force but it doesn’t do anything. At one point it even caused the plane to constantly (barrel roll)rotate in place. I am not a programmer by any means but I am learning, so if someone has a flight script they can share or give me some hints that would be great.

I am not looking for anything realistic I just need to get it in the air and flying at the least and I can adjust and tweak the code to my best ability after.

Thx again

I think you should be more specific in your question:
Maybe show us a code snippet?

We won’t be able to find the reason for the constant barrel roll until we can see what you actually did.

And I doubt there are flight control scripts hanging loose out there.

Assuming you have working joystick input, your problem can be broken into these components:

  1. The airplane needs a forward thrust. This is a force that is applied on your rigid body in FixedUpdate():
  rigidbody.AddForce(transform.forward * inputThrottle * MAX_FORCE_MAGNITUDE);

Where MAX_FORCE_MAGNITUDE is a constant that you define which should be somewhat related to the mass of the rigidbody. A good value to start with here is to have mass * 10. So if the plane weighs 1000 (kg)… you want a max thrust force of 10 000 (newton).

  1. Your airplane needs lift and control. In my opinion the easiest way to achieve a simple flight model is to make a script called Fin. This Fin component, which should be placed on sub objects at approprate places on the airplane, will exert a force on the rigidbody that is related to its up direction compared to the rigid body velocity at the Fin’s position. The higher angle of attack of the Fin, the greater the force it exerts on the rigidbody at the Fin’s position.

The first step is to have the Fins cause lift on your airplane. When you see that it’s working, you can add more fins at appropriate places, that you rotate based on joystick input. This way, you can make joystick-controlled “ailerons” that you simply turn to control the aircraft in a physics-based way.

Now, this is all for fixed-wing aircraft. I’m not sure what you mean by hovercraft, but it’s all physics… and the essential part is that you need to continuously apply forces to counter gravity.

If you don’t have a basic grasp on forces, acceleration, inertia and that kind of stuff, wikipedia has a lot of accessible information.

Every Physics engine I have worked with has it own characteristics. If you have a control scheme that works, start playing around with the physics attributes of the game object(s)drag, etc. Or start assigning the physics attributes when you generate your code. You will be surprised how sensitive the Engine is for Unity. :wink:

i have the same idea some time ago…

I have a Joystick working pretty well. But i cannot detect the right analog to make this Axis or controller.

I would download the USB SDK from Apples dev site for Macs if you are working on a mac. Or simply build a PC game with the options showing at start up. Make sure your joystick is connected to the pc.Mac. Use USB Prober on the mac to find out exactly how the mac registers the joysticks parts… this could be part of your issue. :slight_smile:

If you are on a PC simply use the Options Input screen to determine what the joystick input is. select the axis input you want, then move the joystick’s axis 2 (it should register this way on PCs). This should appear in the input field instead of a null or Joystick Axis 1 input value.

If it does not work contact me via PM.

Cheers

FSP controller with no gravity. Use FSP controller to “fly” / walk around and add a mouse orbit to the camera with a fixed target. The target Atta be your plane. Add restrictions to the “degree x,y,z”

I have a racing game were the cars hover over the ground. Kinda like the old school F-Zero except i use gravity I’m guessing your planes are zipping in 3d space so no need for gravity.

If you still need help, I have a flight sim script I can PM you. It is not “Realistic” per-say but it is close enough to still be fun without hogging resources.

Edit. If anyone else is interested in this I can build it and post in showcase, (initialy I was going to make a true flight sim, but stopped when I realized it was going to be “too realistic to be fun”).

I’ve gotten some PM’s regarding my post above. To clear things up for future readers, I posted my script here: http://forum.unity3d.com/viewtopic.php?t=45396&highlight=flight+sim . My post there contains the unity package file. Note that the scene file was accidentaly left out, to create a new scene just add an empty game object with a child model, and child camera. Attach the flight sim script to the empty game object and edit values and create input accordingly. The script header contains instructions on how to set up the script.