Search Unity

Floating

Discussion in 'Editor & General Support' started by nickavv, Jan 18, 2007.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    You all probably know something about my game RaceCraft by now. Try the attached scene. Even if you fly skillfully you're bound to topple over somewhere. I need to find a way to make the craft more stable, so it won't tip over at all, or make it have a self-righting mechanism. Or both. :p Here's the code I wrote for floating:

    Code (csharp):
    1.  
    2. function FixedUpdate () {
    3.     if (Physics.Raycast (transform.position, Vector3.down, 3)) {
    4.         rigidbody.AddForce (Vector3.up * 4.6);
    5.     }
    6.     var accel = Input.GetAxis ("Vertical") * 2;
    7.     rigidbody.AddRelativeForce (0, 0, accel);
    8.     var h = Input.GetAxis ("Horizontal");
    9.     transform.Rotate (0, h, 0);
    10. }
    EDIT: Actually, FreezeRotation seems to have solved it (duh), but you can still play the buggy web player if you want. lol
     

    Attached Files: