Zone
July 15, 2011, 3:47am
1
Hey, Im having a bit of trouble adding vertical movement. Here is the code.
var pSpeed : float = 12;
var leftBoundary : float = 5;
var rightBoundary : float = 70;
var missile : Rigidbody;
var missileSpeed : float = 10;
var explosion : GameObject;
static var missileInFlight : boolean;
function Start () {
missileInFlight = false;
}
function Update () {
// Move player’s base back and forth and launch missiles
if (InvaderControl.playerCanMove) {
var playerPosition : float = transform.position.x + (Input.GetAxis(“Horizontal”) * Time.deltaTime * pSpeed);
playerPosition = Mathf.Clamp(playerPosition, leftBoundary, rightBoundary);
transform.position.x = playerPosition;
if (Input.GetButtonDown(“Fire1”) !missileInFlight !InvaderControl.levelEnded) {
var missilePosition : Vector3 = transform.position + Vector3.up*3.5;
var missileClone : Rigidbody = Instantiate(missile, missilePosition, Quaternion.identity);
missileClone.velocity.y = missileSpeed;
missileInFlight = true;
}
}
}
function Explode () {
Instantiate(explosion, transform.position, Quaternion.identity);
}
We prefer to be called programmers not scripters. You have to keep updating the velocity if you want it to continue move up. Also your going to run into a problem where you can’t fire another missile after the first unless you set missileInFlight to false in the Explode().
I prefer being called a scripter =/