Creare Videogiochi - Game Developer
Aircraft Script - Versione stampabile

+- Creare Videogiochi - Game Developer (https://www.making-videogames.net/giochi)
+-- Forum: Unity3D Italia (https://www.making-videogames.net/giochi/Forum-Unity3D-Italia)
+--- Forum: Risorse e Programmi per Unity3D (https://www.making-videogames.net/giochi/Forum-Risorse-e-Programmi-per-Unity3D)
+--- Discussione: Aircraft Script (/thread-Aircraft-Script)



Aircraft Script - KillerZ - 22-11-2010

Codice:
/*

TO USE:
Go to Edit menu > Project Settings > Input and make 4 controls:
Throttle (positive button: x)
Roll (negative button: q, positive button e)
Pitch (negative button: up {alt. w}, positive button: down {alt. s})
Yaw (negative button: left {alt. a}, positive button: right {alt. d})
Brake (positive button: z)

To start, just create an empty game object with a rigidbody, and add the script to the gameobject.
Place a camera and/or a primitive into the Gameobject so that you can see the movement (for either 3rd person
or first person airplane).

When ready, press "x" to speed up - once you are fast enough, you can use the other buttons to "fly"

Please refrain from using this script without giving me (Jesse Ofsowitz) credit.

*/
var speed = 0.00;
var rollSpeed = 15.0;
var pitchSpeed = 15.0;
var yawSpeed = 15.0;

function Update() {
    if(Input.GetButton ("Throttle")) speed += Time.deltaTime*5; //Speed up before flying
        transform.Translate (Vector3.forward * speed * Time.deltaTime);
        
        if(speed > 25) {
            Flight(); //An arbitrary # to simulate enough "lift" for the craft to fly
        }
        
        if(speed >= 51) {
            speed -= 1; //So it can't go the speed of light
        }
        
    if(Input.GetButton ("Brake")) speed -= Time.deltaTime*2;
        
        if(speed <= 0) {
            speed = 0; //To slow down, but not go backwards
        }    
}

function Flight()
{
    var roll = -Input.GetAxis ("Roll") * rollSpeed;
    var pitch = -Input.GetAxis ("Pitch") * pitchSpeed;
    var yaw = Input.GetAxis ("Yaw") * yawSpeed;
    
    transform.Rotate (Vector3.forward * roll * Time.deltaTime * 3); //These create ok movements
    // I don't know how to smoothen out the rotations yet...
    // If anyone can make an "ease in" rotation without wasting tons of time/code space, I'd be grateful (hint)
    transform.Rotate (Vector3.right * pitch * Time.deltaTime);
    transform.Rotate (-Vector3.forward * yaw * Time.deltaTime/1.5);
    transform.Rotate (Vector3.up * yaw * Time.deltaTime);
}

Questo è il codice per gli aircraft!


RE: Aircraft Script - Riddick - 22-11-2010

Ottimo, ma chi l'ha fatto ?


RE: Aircraft Script - KillerZ - 22-11-2010

boh non lo so, la scritto un utente nel mio forum (non è suo) ma non so chi l'ha fatto xD