Monday, June 27, 2011

Instantiate a projectile for a Shooter Game

// Instantiate a rigidbody then set the velocity

var projectile : Rigidbody;

function Update () {
// Ctrl was pressed, launch a projectile
if (Input.GetButtonDown("Fire1")) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);

// Give the cloned object an initial velocity along the current
// object's Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
}
}

No comments:

Post a Comment