help with making bullet move toward the mouse pointer

hello guys, i am new at unity and java scripting, i found different solutions for this around here about how to do this but i do not get it.

if(Input.GetAxis("Fire_bullet") Time.time > rate_time)
	{
		rate_time = Time.time + rate;
		Instantiate(bullet_pre, Vector3(transform.position.x, transform.position.y,0), Quaternion.identity);
		
		
	}

the bullet comes out from the parent,
the on another script i have

function Update () {
	bull.Translate(Vector3(speed * Time.deltaTime, 0, 0));
	}

for the speed

how do i make the bullet come out towards the direction of the mouse pointer? thank you for your time

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));
}

try this

No appropriate version of ‘UnityEngine.Transform.LookAt’ for the argument list ‘(UnityEngine.Ray)’ was found.
i get this error :confused:

my bad
check this link out

I hate to be the stickler about this. And I know you say your new to it all. There is an entire reference to all of this:

http://docs.unity3d.com/Documentation/ScriptReference

In that you will find the reference to the Transform object:

http://docs.unity3d.com/Documentation/ScriptReference/Transform.html

In that transform, you will find a reference to the LookAt method:

http://docs.unity3d.com/Documentation/ScriptReference/Transform.LookAt.html

Notice… that LookAt, is has some capitol letters.

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));
	}