hi i want to ask if someone here know how to make something fly like this http://www.youtube.com/watch?v=r_7KHkO_FpM&feature=related if some know it please help me cuz ive very noob at this literally noob 99% noob
Yes, its possible to make it. I recommend you to research flight physics and use rigidbodies and forces to translate it to Unity 3D.
Here is an old vehicle samples script plane portion, it is written in jScript but it should be a great start for you: Code (csharp): //Mass var mass = 1200; //Force of the planes engine var engineForce = 10000.0; //Toruqe coefficient for elevator (pitch) var elevator = 0.3; //Base input for elevator (when no key is pressed), //so plane stays on one height without user input var elevatorCenterSetting = -0.25; //Toruqe coefficient for ailerons (roll) var ailerons = 0.3; //additional drag induced by air brake if present var brakeDrag = 0.0; //drag along x,y and z directions var drag = Vector3(2.0,8.0,0.05); //stabilizing drag along x,y and z axes, causing plane to face forward var stabilizingDrag = Vector3(2.0,1.0,0.0); //ground brake and corner handling capabilities var groundBrakeAccel = 8; var groundCornerAccel = 6; //child to rotate as propeller if available var propeller : Transform; private var queryUserInput = true; private var pitchInput = 0.0; private var rollInput = 0.0; private var thrustInput = 0.0; private var steerVelo : float; private var wheels; private var throttle : float; private var brake : float; private var rpmPitch = 0.0; private var grounded = false; private var propOriginalRotation : Quaternion; private var propSpin = 0.0; function Start () { //Destroy existing rigidbody, we don't want anyone to mess with it. if(rigidbody) Destroy(rigidbody); //setup rigidbody gameObject.AddComponent(Rigidbody); rigidbody.mass = mass; rigidbody.angularDrag = 0.5; rigidbody.interpolation = RigidbodyInterpolation.Interpolate; //start engine noise audio.loop = true; audio.Play(); wheels = transform.GetComponentsInChildren(WheelCollider); if(wheels.Length == 0) Debug.Log("Add some wheel colliders for ground control"); for(w in wheels) { //we use our own simple physics for ground control w.forwardFriction.stiffness = 0; w.sidewaysFriction.stiffness = 0; } if(propeller != null) propOriginalRotation=propeller.localRotation; } //Functions to be used by external scripts //controlling the plane if required //=================================================================== //return a status string for the vehicle function GetStatus(gui : GUIText) { gui.text="v="+(rigidbody.velocity.magnitude * 3.6).ToString("f1") + "km/h \nthrottle="+(throttle*100).ToString("f0") +"%\naltitude="+(transform.position.y).ToString("f1")+"m"; } //return an information string for the vehicle function GetControlString(gui : GUIText) { gui.text="Use arrow keys to control the plane,\nA/Z for throttle control,\nspace for brake."; } //Setup main camera to follow vehicle function SetupCamera() { if(Camera.main.GetComponent(SmoothFollow) != null) Camera.main.GetComponent(SmoothFollow).enabled=false; Camera.main.transform.localRotation=Quaternion.identity; Camera.main.transform.localPosition=Vector3(0,4,-19); Camera.main.transform.parent=transform; } //Enable or disable user controls function SetEnableUserInput(enableInput) { queryUserInput=enableInput; } //Plane physics //====================================================================== //Check if plane is on ground function GroundCheck () { grounded=false; for( w in wheels ) if(w.isGrounded) grounded = true; } //very basic physics for moving the plane around on the ground //uses similar simplified model used for the handling in the car script. function GroundPhysics () { var velo=rigidbody.velocity; var dir=transform.TransformDirection(Vector3.forward); var flatDir=Vector3.Normalize(new Vector3(dir.x,0,dir.z)); var flatVelo=new Vector3(velo.x,0,velo.z); var brakeForce=-flatVelo.normalized*brake*rigidbody.mass*groundBrakeAccel; flatDir*=flatVelo.magnitude; var rev=Vector3.Dot(flatVelo,flatDir)>0?1:-1; flatDir*=rev; var diff=(flatVelo-flatDir).magnitude; var cornerAccel=groundCornerAccel; if(cornerAccel>diff)cornerAccel=diff; var cornerForce=-(flatVelo-flatDir).normalized*cornerAccel*rigidbody.mass; cornerSlip=Mathf.Pow(cornerAccel/groundCornerAccel,3); rigidbody.AddForce(brakeForce+cornerForce); var fVelo=velo.magnitude; var veloSteer=((15/(2*fVelo+1))+1); var maxRotSteer=0.5*Time.fixedDeltaTime*(1-0.8*cornerSlip); var veloFactor=fVelo<1.0?fVelo:Mathf.Pow(fVelo,0.1); var steerVeloInput=rev*rollInput*veloFactor*0.5*Time.fixedDeltaTime; if(fVelo<0.1) steerVeloInput=0; if(steerVeloInput>steerVelo) { steerVelo+=0.02*Time.fixedDeltaTime*veloSteer; if(steerVeloInput<steerVelo) steerVelo=steerVeloInput; } else { steerVelo-=0.02*Time.fixedDeltaTime*veloSteer; if(steerVeloInput>steerVelo) steerVelo=steerVeloInput; } steerVelo=Mathf.Clamp(steerVelo,-maxRotSteer,maxRotSteer); transform.Rotate(Vector3.up*steerVelo*57.295788); } //physics for moving the plane through the air function AirPhysics () { //engine force rigidbody.AddForce(transform.forward*engineForce*throttle); //wings and drag forwardVelo = Vector3.Dot(rigidbody.velocity,transform.forward); sqrVelo = forwardVelo*forwardVelo; dragDirection = transform.InverseTransformDirection(rigidbody.velocity); dragAndBrake = drag+Vector3(0,0,brakeDrag*brake); dragForces = -Vector3.Scale(dragDirection,dragAndBrake)*rigidbody.velocity.magnitude; rigidbody.AddForce(transform.TransformDirection(dragForces)); //stabilization (to keep the plane facing into the direction it's moving) stabilizationForces = -Vector3.Scale(dragDirection,stabilizingDrag)*rigidbody.velocity.magnitude; rigidbody.AddForceAtPosition(transform.TransformDirection(stabilizationForces),transform.position-transform.forward*10); rigidbody.AddForceAtPosition(-transform.TransformDirection(stabilizationForces),transform.position+transform.forward*10); //elevator rigidbody.AddTorque(transform.right*sqrVelo*elevator*(pitchInput+elevatorCenterSetting)); //ailerons if(!grounded) rigidbody.AddTorque(-transform.forward*sqrVelo*ailerons*rollInput); //rudder // rigidbody.AddTorque(transform.up*sqrVelo*rudder*inputAxes.x); //sound rpmPitch=Mathf.Lerp(rpmPitch,throttle,Time.deltaTime*0.2); audio.pitch=1.0+1.0*rpmPitch; audio.volume=0.4+throttle; //prop if(propeller != null) { propMotion=Mathf.Clamp(Time.deltaTime*rpmPitch*360*50,0,43); propSpin = Mathf.Repeat( propSpin+propMotion , 360); propeller.localRotation=Quaternion.Euler( 0,0,propSpin)*propOriginalRotation; propeller.renderer.material.SetColor("_BlurColor",Color(1,1,1,rpmPitch)); } } function FixedUpdate () { //query input axes if necessarry pitchInput = 0.0; rollInput = 0.0; thrustInput = 0.0; if(queryUserInput) { pitchInput = Input.GetAxis("Vertical"); rollInput = Input.GetAxis("Horizontal"); thrustInput = Input.GetAxis("Thrust"); } //check if plane is on ground GroundCheck(); //update throttle brake throttle=Mathf.Clamp01(throttle + thrustInput * Time.deltaTime * 0.3); brake=Input.GetButton("Jump")?1.0:0.0; //Air Physics AirPhysics(); //Ground Physics if on ground if(grounded) GroundPhysics(); } //Destroy Airplane if crashed into something function OnCollisionEnter(collision : Collision) { //Only crashed when touching something with the wings, wheels should not crash if(collision.contacts[0].thisCollider.tag=="DestructiveCollider") BroadcastMessage("ApplyDamage",Mathf.Infinity,SendMessageOptions.DontRequireReceiver); } //Called by DamageReceiver if plane crashed function Detonate() { //no more flying enabled = false; //destroy wheels for( w in wheels ) w.gameObject.active=false; //Mark object no longer a target for homing missiles. if(tag=="MissileTarget") tag=""; //turn off engine audio.volume=0; if(propeller != null) propeller.renderer.material.SetColor("_BlurColor",Color(1,1,1,0)); } @script RequireComponent (AudioSource)
Not to be digging up an old post ive trying using this on an airplane but I get a lot of errors any help?
Sorry to resurrect this again (it's not that old though!) but I've been trying to use this script in a test scene. Aside from calibrating the thrust and rigidbody weight to match the model's scale, I'm having a big issue with the physics. The aircraft is jittering/shuddering immensely. In level flight, the aircraft looks as though it's occupying three different rotations in the y-axis, all within about 15 degrees of 'normal', and the aircraft is oscillating between them faster than I can see. I'm sure this is an issue to do with the rigidbody physics and the way the script is applying forces perhaps, but I've tried many different settings, including rigidbody interpolation (all three settings) to see if they are the cause of the problem, but no luck. :? I've searched the forums and the only stuff I can find to do with sort of jittering are regarding character controllers. Can anyone shed a little light on this please?
This is a good script, but I also have problem with the airplane. The aircraft is jittering/shuddering immensely. Anybody have a solution? or another easy working script?
@quy17114729 the respondents in this thread haven't logged into the forum for over a year (if not more)...
Hey everyone, if you are still looking at this thread, and it has been a long time, just let me know so I can try to help..