• Benvenuto in Making Videogames!
  • Dai sfogo alla tua fantasia!
  • Crea il tuo Videogioco!
Benvenuto ospite! Login Registrati




Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5
Aircraft Script
#1
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!
 
Rispondi
  


Messaggi in questa discussione
Aircraft Script - da KillerZ - 22-11-2010, 04:27 PM
RE: Aircraft Script - da Riddick - 22-11-2010, 04:29 PM
RE: Aircraft Script - da KillerZ - 22-11-2010, 04:30 PM

Vai al forum:


Browsing: 1 Ospite(i)