function Update () {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); // Construct a ray from the current mouse coordinates
bull.transform.lookAt(ray); //make the bullet look towards mousePosition on Update, and then translate with your original script
bull.Translate(Vector3(speed * Time.deltaTime, 0, 0));
}
Look at does not accept a Ray in one of its overloaded methods. It accepts a Transform or a Vector3.
This means that xxsur’s code is actually incomplete. He gets the ray, but does nothing with it. (a ray is a point of origin and a direction, thats it)
So below is the code (with added code) to convert the ray coming from the mouse to a position in space relative to the bullet.
function Update () {
// Construct a ray from the current mouse coordinates
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
// capture the forward position of the bullet
var lookAt : Vector3 = bull.transform.position + bull.transform.forward * 10;
// create a plane in front of the bullet
var plane : Plane = new Plane(bull.transform.forward, lookAt);
// do a plane.Raycast from the mouse ray to the plane in front of the bullet
var dist : float;
if(plane.Raycast(ray, dist)){
// if it hits, "bend" the bullet lookAt point towards that point.
lookAt = Vector3.Lerp(lookAt, ray.GetPoint(dist), 5 * Time.deltaTime);
}
// assign the bullet's facing.
bull.transform.LookAt(lookAt);
bull.Translate(Vector3(speed * Time.deltaTime, 0, 0));
}