Unity Community


Results 1 to 13 of 13

  1. Posts
    40

    Physics-based flight script...hard to control though...

    Hi guys,

    I've come up with the following code for a physics-based flight model. It's a very simple script:

    Code:  
    1. #pragma strict
    2.  
    3. var rollSpeed : float = 100.0; //rolling rotation speed
    4.  
    5. var pitchSpeed : float = 100.0; //vertical rotation speed
    6.  
    7. var yawSpeed : float = 100.0; //horizontal rotation speed
    8.  
    9. var accelerate : float = 20000; //main engine thrust
    10.  
    11.  
    12. var rotSpeed = 15;
    13.  
    14. var planform;
    15.  
    16. var thrust : float = 0;
    17. var maxThrust : float = 600000;
    18.    
    19. var liftFactor : float = 0.1;
    20.  
    21. var crashThreshold = 10.0;
    22.  
    23. var crashSound : AudioSource;
    24.  
    25. private var oldVelocity : float;
    26.    
    27. private var speed : float = 0.0;
    28.  
    29.  
    30. // Use this for initialization
    31. function Start ()
    32. {
    33.     animation["Flying"].wrapMode = WrapMode.Loop;
    34.    
    35.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    36.     crashThreshold *= crashThreshold;   // So it works with sqrMagnitude
    37. }
    38.  
    39. function CrashCheck()
    40. {
    41.     if (oldVelocity - rigidbody.velocity.sqrMagnitude > crashThreshold) {
    42.         // TODO: Proper Crash Code
    43.         crashSound.Play();
    44.         Debug.Log("Penguin Crashed!!!");
    45.     }
    46.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    47. }
    48.    
    49. function KeepInBounds()
    50. {
    51.     //Wrap the penguin around the playfield so that you cannot fly under the landscape
    52.        
    53.     if (transform.position.x >= 1900.0) transform.position.x = 0;
    54.     else if (transform.position.x <= -1900.0) transform.position.x = 1900.0;
    55.     else if (transform.position.z >= 1900.0) transform.position.z = 0;
    56.     else if (transform.position.z <= -1900.0) transform.position.z = 1900.0;
    57.  
    58.     //Limit the height
    59.     if (transform.position.y > 1000) transform.position.y = 1000;
    60.        
    61.     animation.CrossFade("Flying");
    62. }
    63.     function FixedUpdate()
    64.     {
    65.         UpdateFunction();
    66.         CrashCheck();
    67.         KeepInBounds();
    68.     }
    69.    
    70.     function UpdateFunction()
    71.     {
    72.          
    73.         var addRot : Quaternion = Quaternion.identity;
    74.        
    75.         var roll : float = 0;
    76.         var pitch : float = 0;
    77.         var yaw : float = 0;
    78.         var lift : float = 0;
    79.        
    80.         roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed);
    81.         pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed);
    82.         yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed);
    83.         thrust = Input.GetAxis("Throttle") * (Time.deltaTime * accelerate);
    84.         lift = Input.GetAxis("Throttle") * (Time.deltaTime * rigidbody.velocity.y * liftFactor);
    85.  
    86.         rigidbody.AddTorque(-pitch, yaw, -roll);
    87.         if (thrust >= 0)
    88.         rigidbody.AddRelativeForce(0,thrust, lift);
    89.        
    90.         //TODO: Add force at two points on a wing for stability
    91.        
    92.         KeepInBounds();
    93.     }

    However, it's a bit tricky to fly. For example, if you use keyboard controls for the four axes, you have to be really careful with pressing the keys, otherwise you can easily enter a spin. Moreover, if you try using a gamepad with the right stick controlling, say, pitch and roll, with the right stick controlling the throttle and yaw, you can also get into a spin extremely easily. Does anyone have any suggestions for making it more stable? After all, you can't have something suddenly go from moving predictably on one axis, only for it to go totally haywire the next moment.

    MachCUBED
    Last edited by MachCUBED; 04-01-2012 at 06:11 PM.

  2. Heu Heu is offline

    Location
    United States
    Posts
    223
    Well if its physic-based i think you can try to change up the physic to your liking by going to

    Edit>Project Settings>Physic

    Then adjust till you like it. I'm not entirely sure about this though.
    Check out my Work In Progress Horror Game!
    -----------------------------------------------------------------------------
    Play Pixel Pirates [its only a small test]
    Play Fatty Flyer <-- I cloned Flappy Bird! Everyone shame me! SHAAAAAAMEEE MEE!!!!!!!
    -----------------------------------------------------------------------------
    Check out my Ludum Dare 23 Entry Here

    Reworking Blog.
    My Portfolio


  3. Posts
    399
    The biggest problem with your code is that I believe AddTorque requires a vector (or components thereof) in world space, not local space. So you ought to use AddRelativeTorque instead here.

    Also, you might need to think about the shape of the object you're flying and set an appropriate inertia tensor. This could for example make it more responsive to roll torque than yaw or pitch torque.

    Your model is also ignoring air resistance, and this is quite important for aircraft as most aircraft are designed to be self-stabilising - so if left to their own devices they will yaw to align with the direction of travel, and roll to level.

    You don't need a complicated aerodynamic model, but I think you do need to put in an extra force proportional to the non-forwards velocity of the plane. Then consider fading out the yaw and pitch inputs when the plane is not flying fairly close to the current facing direction in the corresponding axis - this prevents excessive inputs from causing more and more spin in an unrealistic way.

    Overall though, I expect your main problem is applying your torques in world space when you should be doing it in local space.


  4. Posts
    40
    Thanks for the tips George Foot, I can't believe I didn't spot the AddRelativeTorque fluke. I fixed it, so now it works significantly better. It's still a bit tricky, so I'll also implement the inertia tensor fixes and other suggestions that you made, then post the results here.
    Last edited by MachCUBED; 04-01-2012 at 06:10 PM.


  5. Location
    NZ
    Posts
    2,933
    There is probably a way to calculate it from world torque, but there is no variable that stores the localtorque.. would be really useful as to stop your plane from spinning, you either have to set the angulardrag or add negative force.
    www.fingerbait.com :: Inferno - Multiplayer SciFi RTS :: Free Console

    Don't mind me, I'm just a Negative Nancy.


  6. Posts
    40
    The angular drag was initially 0.5, with a main drag of 0.5 as well. Changing the angular drag to 2 while leaving the main drag the same fixed my spin problem, while setting the angular drag to 5 made things too sluggish.


  7. Location
    NZ
    Posts
    2,933
    The problem with that method is it stops all rotation... if you only want it to stop rotating around one axis, you need to apply negative force...
    www.fingerbait.com :: Inferno - Multiplayer SciFi RTS :: Free Console

    Don't mind me, I'm just a Negative Nancy.


  8. Posts
    40
    After dealing with some other aspects of my game, I decided to try refining my code to add negative force as additional rotational drag for the roll axis (and only the roll axis). This is what I came up with:

    Code:  
    1. #pragma strict
    2.  
    3. var rollSpeed : float = 100.0; //rolling rotation speed
    4.  
    5. var pitchSpeed : float = 100.0; //vertical rotation speed
    6.  
    7. var yawSpeed : float = 100.0; //horizontal rotation speed
    8.  
    9. var accelerate : float = 20000; //main engine thrust
    10.  
    11.  
    12. var rotSpeed = 15;
    13.  
    14. var leftForwardWing : GameObject;
    15.  
    16. var rightForwardWing : GameObject;
    17.  
    18. var leftTailPlane : GameObject;
    19.  
    20. var rightTailPlane : GameObject;
    21.  
    22. var thrust : float = 0;
    23.  
    24. var maxThrust : float = 600000;
    25.  
    26. var rollDragFactor : float = 1;
    27.  
    28. var liftFactor : float = 0.1;
    29.  
    30. var crashThreshold = 10.0;
    31.  
    32. var crashSound : AudioSource;
    33.  
    34. private var oldRoll : float = 0;
    35.  
    36. private var oldVelocity : float;
    37.    
    38. private var speed : float = 0.0;
    39.  
    40. // Use this for initialization
    41. function Start ()
    42. {
    43.     animation["Flying"].wrapMode = WrapMode.Loop;
    44.    
    45.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    46.     crashThreshold *= crashThreshold;   // So it works with sqrMagnitude
    47.        
    48.     //posX = transform.position.x;
    49.     //posY = transform.position.y;
    50.     //posZ = transform.position.z;
    51.        
    52.     //rigidbody.AddForce(0,accelerate.y,0);
    53. }
    54.  
    55. function CrashCheck()
    56. {
    57.     if (oldVelocity - rigidbody.velocity.sqrMagnitude > crashThreshold) {
    58.         // TODO: Proper Crash Code
    59.         crashSound.Play();
    60.         Debug.Log("Penguin Crashed!!!");
    61.     }
    62.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    63. }
    64.    
    65. function KeepInBounds()
    66. {
    67.     //Wrap the penguin around the playfield so that you cannot fly under the landscape
    68.        
    69.     if (transform.position.x >= 1900.0) transform.position.x = 0;
    70.     else if (transform.position.x <= -1900.0) transform.position.x = 1900.0;
    71.     else if (transform.position.z >= 1900.0) transform.position.z = 0;
    72.     else if (transform.position.z <= -1900.0) transform.position.z = 1900.0;
    73.  
    74.     //Limit the height
    75.     if (transform.position.y > 1000) transform.position.y = 1000;
    76.        
    77.     animation.CrossFade("Flying");
    78. }
    79. function FixedUpdate()
    80. {
    81.     UpdateFunction();
    82.     CrashCheck();
    83.     KeepInBounds();
    84. }
    85.    
    86. function UpdateFunction()
    87. {
    88.     //Get inputs
    89.        
    90.     var roll : float = 0;
    91.     var pitch : float = 0;
    92.     var yaw : float = 0;
    93.     var lift : float = 0;
    94.        
    95.     roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed);
    96.     pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed);
    97.     yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed);
    98.     thrust = Input.GetAxis("Throttle") * (Time.deltaTime * accelerate);
    99.     lift = Input.GetAxis("Throttle") * (Time.deltaTime * rigidbody.velocity.y * liftFactor);
    100.        
    101.     oldRoll = roll;
    102.        
    103.         //Rotate the penguin on its axes
    104.     if (Input.GetAxis("Roll") == 0)
    105.         rigidbody.AddRelativeTorque(-pitch, yaw, oldRoll * rollDragFactor);
    106.     else
    107.         rigidbody.AddRelativeTorque(-pitch, yaw, -roll);
    108.        
    109.     // Move forwards
    110.     if (thrust >= 0)
    111.         rigidbody.AddRelativeForce(0,0, thrust);
    112.        
    113.     // Generate lift
    114.     rigidbody.AddForceAtPosition(Vector3(0, lift, 0), leftForwardWing.transform.position);
    115.     rigidbody.AddForceAtPosition(Vector3(0, lift, 0), rightForwardWing.transform.position);
    116.    
    117.     rigidbody.AddForceAtPosition(Vector3(0, lift, 0), leftTailPlane.transform.position);
    118.     rigidbody.AddForceAtPosition(Vector3(0, lift, 0), rightTailPlane.transform.position);
    119.        
    120.     KeepInBounds();
    121. }
    Last edited by MachCUBED; 04-06-2012 at 06:15 PM. Reason: Code updated


  9. Posts
    399
    You can get the angular velocity from the physics, convert it into local space, isolate components and apply any asymmetric angular drag functions you like. It all behaves mostly like the linear equivalents, and you won't go far wrong by just doing the obvious thing.


  10. Location
    Kerbal Space Program Forums
    Posts
    175
    I recently threw together a Javascript that may help you with this flight problem...


    var speed = 50.0;
    var rotateSpeed = 10.0;

    function Update () {
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed;
    var y = Input.GetAxis("Roll") * Time.deltaTime * rotateSpeed;
    var z = Input.GetAxis("Vertical") * Time.deltaTime * rotateSpeed;
    var accel = Input.GetAxis("Jump") * Time.deltaTime * speed;
    rigidbody.AddRelativeForce(0, 0, accel);
    rigidbody.AddRelativeTorque(z, x, -y);
    }


    Just attach this and a rigidbody (yes gravity for atmospheric flight, none for space) to your plane or spaceship game object and set the drag and angular drag (on rigidbody) to something between 1 and 10, then set the speed (on script inspector) to the drag * 1000, and the rotateSpeed (on script inspector) to the angular drag * 200 for a simple flight style. You can mess with the speed, drag, rotateSpeed, and angular drag to affect how your little flyer handles. You'll also need to create a new input (edit>project settings>input) called "Roll" and set the buttons to get its input for the script. Let me know if you need any specifications for the settings on the "Roll" input.

    Controls: w/s for down/up angle, a/d for left/right turn, q/e for left/right rotate (do a barrel roll when you test it out!), space bar for acceleration.

    You could also change "rigidbody.AddRelativeForce" and "rigidbody.AddRelativeTorque" to "transform.Translate" and "transform.Rotate," respectively, in order to make the controls more responsive, but it's also kinda dull to fly that way...

    C&C appreciated!

    -Orbitus2


  11. Posts
    40
    Asa matter of fat, your solution is pretty similar to mine:

    Code:  
    1. var rollSpeed : float = 100.0; //rolling rotation speed
    2.  
    3. var pitchSpeed : float = 100.0; //vertical rotation speed
    4.  
    5. var yawSpeed : float = 100.0; //horizontal rotation speed
    6.  
    7. ...
    8.  
    9. function UpdateOrientation()
    10. {
    11.  
    12.         var roll : float = 0;
    13.         var pitch : float = 0;
    14.         var yaw : float = 0;
    15.        
    16.         //Get inputs
    17.        
    18.         if (isControllable)
    19.         {
    20.             roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed);
    21.             pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed);
    22.             yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed);
    23.            
    24.             thrust += Input.GetAxis("Throttle") * (Time.deltaTime * accelerate);
    25.            
    26.             if (Mathf.Abs(thrust) > maxThrust)
    27.             {
    28.                 if (thrust > 0)
    29.                     thrust = maxThrust;
    30.             }
    31.             else if (thrust < 0)
    32.                     thrust = 0;
    33.            
    34.             animation["Flying"].speed = (rigidbody.velocity.magnitude * thrust / 10000);
    35.            
    36.             //Rotate the penguin on its axes
    37.             if (Input.GetAxis("Roll") == 0)
    38.                 rigidbody.AddRelativeTorque(-pitch, yaw, -oldRoll * rollDragFactor);
    39.             else
    40.                 rigidbody.AddRelativeTorque(-pitch, yaw, -roll);
    41.         }
    42.         else
    43.         {
    44.             thrust = (Time.deltaTime * accelerate);
    45.             lift = thrust * (rigidbody.velocity.z * liftFactor);
    46.         }
    47.        
    48.         lift = Mathf.Abs(rigidbody.velocity.z * liftFactor);
    49.        
    50.         oldRoll = roll;
    51.        
    52.         // Move forwards
    53.         if (thrust >= 0)
    54.             rigidbody.AddRelativeForce(0,lift, thrust);
    55.            
    56.         // Fire exhaust
    57.        
    58.         if (thrust <= 0)
    59.         {
    60.             exhaust.Stop();
    61.             exhaust.Clear();
    62.         }
    63.         else
    64.         {
    65.             exhaust.Play();
    66.             exhaustLight.intensity = Mathf.Abs(thrust / maxThrust);
    67.             if (thrust > 0)
    68.                 exhaust.emissionRate = (thrust / maxThrust) * 2000;
    69.         }
    70. }

    You can adjust the different rotation speeds to create different turning effects. Thanks for the contribution.

    MachCUBED


  12. Location
    Kerbal Space Program Forums
    Posts
    175
    No problem, and you were the one who got me thinking, so thanks to you as well!

    -Orbitus2


  13. Posts
    40
    Here's a new version for iOS devices. Unfortunately, it's really touchy on roll inputs, while being sluggish on pitch inputs. This data is from a rigidbody with a mass of 0.5kg, angular drag of 0.05, and drag of 0.0025.

    Code:  
    1. #pragma strict
    2.  
    3. var rollSpeed : float = 0.0005; //rolling rotation speed
    4.  
    5. var pitchSpeed : float = 125.0; //vertical rotation speed
    6.  
    7. var yawSpeed : float = 1000.0; //horizontal rotation speed
    8.  
    9. var accelerate : float = 600; //main engine thrust
    10.  
    11.  
    12. var thrust : float = 1;
    13.  
    14. var groundHit : RaycastHit;
    15.  
    16. var maxThrust : float = 5;
    17.  
    18. var rollDragFactor : float = 5;
    19.  
    20. var liftFactor : float = 0.3;
    21.  
    22. var crashThreshold = 10.0;
    23.  
    24. var crashSound : AudioClip;
    25.  
    26. var stallWarning : AudioClip;
    27.  
    28. var voiceSounds: AudioClip[];
    29.  
    30. var poopChute : ParticleSystem;
    31.  
    32. var maxHeight : int = 1000;
    33.  
    34. var flightBounds : Vector2 = Vector2(1000,1000);
    35.  
    36. var maxLife : int = 100;
    37.  
    38. var life : int = maxLife;
    39.  
    40. var throttlePad : Joystick;
    41.  
    42. private var oldRoll : float = 0;
    43.  
    44. private var oldVelocity : float;
    45.    
    46. private var speed : float = 0.0;
    47.  
    48. private var lift : float = 0;
    49.  
    50. private var sensitivity : float = 1.0;
    51.  
    52. private var controlType : String;
    53.  
    54. protected var isControllable = true;
    55.  
    56. private var gyroBool : boolean;
    57.  
    58. private var gyro : Gyroscope;
    59.  
    60. private var rotFix : Quaternion;
    61.  
    62.  
    63. // Use this for initialization
    64.  
    65. function Start ()
    66. {
    67.     animation["Flying"].wrapMode = WrapMode.Loop;
    68.    
    69.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    70.     crashThreshold *= crashThreshold;   // So it works with sqrMagnitude
    71.    
    72.     NotificationCenter.DefaultCenter().AddObserver(this, "PlayerDeactivated");
    73.     NotificationCenter.DefaultCenter().AddObserver(this, "PlayerControllable");
    74.    
    75.     //Setup controls
    76.    
    77.      gyroBool = SystemInfo.supportsGyroscope;
    78.      
    79.      if (gyroBool)
    80.      {
    81.  
    82.         gyro = Input.gyro;
    83.  
    84.         gyro.enabled = true;
    85.  
    86.         if (Screen.orientation == ScreenOrientation.LandscapeRight)
    87.         {
    88.             rotFix = Quaternion(0,0,0.7071,0.7071);
    89.         }
    90.     }
    91.     else
    92.     {
    93.         // Add accelerometer controls and/or keyboard/gamepad controls
    94.         print("NO GYRO");
    95.  
    96.     }
    97.    
    98.     sensitivity = PlayerPrefs.GetFloat("Sensitivity", 1.0);
    99.    
    100.     // Setup lifespan and thrust from PlayerPrefs
    101.    
    102.     var defaultMaxThrust : int = maxThrust;
    103.     maxThrust = PlayerPrefs.GetInt("Thrust", defaultMaxThrust);
    104.    
    105.     var defaultMaxLife : int = maxLife;
    106.     maxLife = PlayerPrefs.GetInt("Life", defaultMaxLife);
    107.    
    108.     life = maxLife;
    109. }
    110.  
    111. function DistressHonk()
    112. {
    113.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    114.     life -= oldVelocity / 100;
    115.        
    116.     if (life <= 0)
    117.     {
    118.         life = 0;
    119.         PlayerDeactivated();
    120.     }
    121.    
    122.     oldVelocity = rigidbody.velocity.sqrMagnitude;
    123. }
    124.    
    125. function KeepInBounds()
    126. {
    127.     //Wrap the penguin around the playfield so that you cannot fly under the landscape
    128.        
    129.     if (transform.position.x >= flightBounds.x / 2) transform.position.x = flightBounds.x / 2;
    130.     else if (rigidbody.position.x <= -(flightBounds.x / 2)) rigidbody.position.x = -(flightBounds.x / 2);
    131.     else if (rigidbody.position.z >= flightBounds.y / 2) rigidbody.position.z = flightBounds.y / 2;
    132.     else if (rigidbody.position.z <= -(flightBounds.y / 2)) rigidbody.position.z = -(flightBounds.y / 2);
    133.  
    134.     //Limit the height
    135.     if (transform.position.y > maxHeight) transform.position.y = maxHeight;
    136. }
    137. function FixedUpdate()
    138. {
    139.     animation.CrossFade("Flying");
    140.  
    141.     Physics.Raycast( rigidbody.position - Vector3.up, -Vector3.up, groundHit );
    142.    
    143.     UpdateOrientation();
    144.     CheckWarnings();
    145.     KeepInBounds();
    146.     PlayVoiceAudio();
    147. }
    148.    
    149. function UpdateOrientation()
    150. {
    151.  
    152.         var roll : float = 0;
    153.         var pitch : float = 0;
    154.         var yaw : float = 0;
    155.        
    156.         var dir : Vector3 = Vector3.zero;
    157.        
    158.         //Get inputs
    159.        
    160.         if (isControllable)
    161.         {
    162.             // we assume that the device is held parallel to the ground
    163.             // and the Home button is in the right hand
    164.            
    165.             // remap the device acceleration axis to game coordinates:
    166.             //  1) XY plane of the device is mapped onto XZ plane
    167.             //  2) rotated 90 degrees around Y axis
    168.            
    169.             if (gyroBool)
    170.             {
    171.                 dir.x = gyro.rotationRateUnbiased.y; // Pitch
    172.                 dir.z = gyro.rotationRateUnbiased.x; // Yaw
    173.                 dir.y = -gyro.rotationRateUnbiased.z; // Roll
    174.             }
    175.             else
    176.             {
    177.                 dir.x = -Input.acceleration.y; // Pitch
    178.                 dir.z = Input.acceleration.x; // Yaw
    179.                 dir.y = Input.acceleration.z; // Roll
    180.             }
    181.            
    182.             // clamp acceleration vector to the unit sphere
    183.             if (dir.sqrMagnitude > 1)
    184.                 dir.Normalize();
    185.  
    186.             // Make it move at a consistent rate per time step...
    187.             dir *= Time.deltaTime;
    188.            
    189.             roll = dir.y * (Time.deltaTime * rollSpeed) * sensitivity;
    190.             pitch = dir.x * (Time.deltaTime * pitchSpeed) * sensitivity;
    191.             yaw = dir.z * (Time.deltaTime * yawSpeed) * sensitivity;
    192.            
    193.             thrust += (throttlePad.position.y) * (Time.deltaTime * accelerate);
    194.    
    195.             /*
    196.             // Code for Desktop version, if one is made in the future.
    197.            
    198.             roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed) * sensitivity;
    199.             pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed) * sensitivity;
    200.             yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed) * sensitivity;
    201.            
    202.             thrust += Input.GetAxis("Throttle") * (Time.deltaTime * accelerate);
    203.             */
    204.            
    205.             if (Mathf.Abs(thrust) > maxThrust)
    206.             {
    207.                 if (thrust > 0)
    208.                     thrust = maxThrust;
    209.             }
    210.             else if (thrust < 0)
    211.                     thrust = 0;
    212.            
    213.             animation["Flying"].speed = (rigidbody.velocity.magnitude / 10);
    214.            
    215.             //Rotate the pigeon on its axes
    216.             rigidbody.AddRelativeTorque(-pitch, yaw, -roll);
    217.         }
    218.         else
    219.         {
    220.             thrust = (Time.deltaTime * accelerate);
    221.             lift = thrust * (rigidbody.velocity.z * liftFactor);
    222.         }
    223.        
    224.         lift = Mathf.Abs(rigidbody.velocity.z * liftFactor);
    225.        
    226.         oldRoll = roll;
    227.        
    228.         // Move forwards
    229.         if (thrust >= 0)
    230.             rigidbody.AddRelativeForce(0,lift, thrust);
    231. }
    232.  
    233. function PlayVoiceAudio()
    234. {
    235. /*
    236.     if (rigidbody.velocity.magnitude * 3.6 == 100 || rigidbody.velocity.magnitude * 3.6 == 200 || rigidbody.velocity.magnitude * 3.6 == 500 || rigidbody.velocity.magnitude * 3.6 == 1000)
    237.     {
    238.         //Honk
    239.         if (audioSource.isPlaying)
    240.             return; // don't play a new sound while the last hasn't finished
    241.        
    242.         audioSource.clip = voiceSounds[Random.Range(0,voiceSounds.length)];
    243.         audioSource.Play();
    244.     }
    245.     */
    246. }
    247.  
    248. function CheckWarnings()
    249. {
    250.  
    251.     // Stall warning - for when there is no lift being generated
    252.    
    253.     //Debug.Log("Lift force:" + lift);
    254.    
    255.     if (lift <= 0)
    256.     {
    257.         audio.clip = stallWarning;
    258.         if (audio.isPlaying == false)
    259.             audio.Play();
    260.     }
    261.     else
    262.     {
    263.         if (audio.clip == stallWarning)
    264.             audio.Stop();
    265.     }
    266.  
    267. }
    268.  
    269. function OnCollisionEnter ()
    270. {
    271.     audio.clip = crashSound;
    272.     audio.Play();
    273.     DistressHonk();
    274. }
    275.  
    276. function PlayerDeactivated ()
    277. {
    278.     isControllable = false;
    279. }
    280.  
    281. function PlayerControllable ()
    282. {
    283.     isControllable = true;
    284. }

    Does anyone have any feedback or suggestions?

    MachCUBED
    Last edited by MachCUBED; 07-30-2012 at 11:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •