# Moving and firing a projectile?

Hello. I got this script from someone on the forums (credit goes to BigMisterB, he was very helpful), its purpose is to allow the player to control a space ship just like in this game (the ship looks at the mouse, it moves forward, and the camera stays behind the ship). Anyways, when I try to instantiate a projectile (which has a script attached to it that moves it forward), simply put, it doesn't work. The projectile just disappears. It appears that the ship is passing the projectile, but even when I set the projectile's speed to much faster than the ship's, it still happens. Does anyone have any ideas as to what is wrong?

Thanks

``````var speed=10.0;
var UDLRspeed=1.0;
var cam : Transform;
var camDistance=20.0;

function Start(){
transform.position=cam.position + cam.forward * camDistance;
}

function Update(){
// find the point where we have our mouse in relation to our ship.
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var plane : Plane=new Plane(Camera.main.transform.forward, transform.position + transform.forward);
var dist : float=0.0;
plane.Raycast(ray, dist);

// get the relative and world position of the mouse.
var worldMouse=ray.origin+ray.direction * dist;
var relativeMouse=transform.InverseTransformPoint(worldMouse);

//assign rotations based on the relative mouse position
transform.localEulerAngles.x=-relativeMouse.y* 10;
transform.localEulerAngles.y= relativeMouse.x* 10;
transform.localEulerAngles.z=-relativeMouse.x* 1;

// do world move of the player towards the world position of the mouse
transform.position=Vector3.Lerp(transform.position, worldMouse, UDLRspeed * Time.deltaTime);

// calculate the speed based off of if we have the left shift key down
var sp=speed;
if(Input.GetKey(KeyCode.LeftShift))sp=sp * 5;

// update the position of the camera and player based off wher the camera is looking.
cam.position+=cam.forward * sp;
var camoffset=cam.InverseTransformPoint(transform.position);
camoffset.z=camDistance;
transform.position=cam.TransformPoint(camoffset);
}

``````

EDIT My bad, here is the projectile script

``````var speed = 40;
var destroy = 5;

function Update () {
transform.Translate(Vector3.forward *speed *Time.deltaTime);Destroy (gameObject, destroy);
}

``````

Is the projectile colliding with the player and being destroyed?

Edit: And the script for the projectile is likely to be more useful.

The script you posted moves your plane and doesn't have anything to do with a projectile. So unless the projectile has its own script that considers collisions with other objects nothing happens, because you didn't tell unity what it should do if you have a collision. That is assuming that your objects DO collide and you set the colliders and rigidbodies up correctly.