Code I never touched during an edit no longer works

I’m at least 99% sure I never touched this code. Yet after finishing up the edit and hitting rebuild the behavior in unity is perplexing. After half an hour of work I give up.

My code:

`
		void fire (Vector3 bulletSpawn)
		{	
				bullet = Instantiate (bulletPrefab, bulletSpawn, Quaternion.identity) as GameObject;
				bullet.rigidbody.transform.LookAt (worldTarget);

				bullet.rigidbody.AddForce ( Vector3.forward * DestroyBulletScript.rateOfMovement);
				//print ("----SHOT [" + c + "]OUT!----");
				c++;
		}
`

What this should do is spawn a bulletPrefab at the bulletSpawn position, orient it toward the worldTarget and send it on its way.

In the past I had different code here; which was much more efficient. Premature optimization is a damn crime but I like framerates.

After an uncountable number of edits this code stopped doing what it originally did, and I had not touched this code at that point either. Which brings us to this.

World target contains the proper values, the bulletSpawn is non-null, and everything should be working. I am at my wits end!

[Edit]: The code should spawn (instantiate) a bulletPrefab at the bulletSpawn position, make it look toward the worldTarget and then use addforce (or set the velocity) to send in the direction of the worldTarget.

As it is right now it looks at the worldTarget but does not travel towards it. Every projectile travels in the same direction (+Z forward). I would assume this is because of my Vector3.Forward * DestroyBullet.rateOfMovement calculation but the thing is this did not go wrong in the past. I thought making the object “look at” the world target and then calling addForce() or setting its velocity using Vector3.forward would send it forward towards the target.

There are no error messages and this function is indeed being called. I’ve used print() statements to debug it so that’s how I know the worldTarget and other variable’s are set correctly.

Am I crazy and this is doing what it is supposed to or is there something wrong with my monodevelop?

Ok so I fixed it… this is what happens when you’re trying to script and on the edge of falling asleep.

This is what I did to fix it:

		void fire (Vector3 bulletSpawn)
		{	
		Vector3 dir = (worldTarget - bulletSpawn).normalized; //Find the normalized direction to the worldtarget
				print ("WorldTarget is:   " + worldTarget + "  and bulletSpawn is:  " + bulletSpawn + " and rateOfMovement is:  " + DestroyBulletScript.rateOfMovement) ;
		bullet = Instantiate (bulletPrefab, bulletSpawn, Quaternion.Euler (dir.x, dir.y, dir.z) ) as GameObject; //Spawn a bullet at the gunbarrel
				bullet.transform.LookAt (worldTarget);  //Orient the bullet toward the worldTarget

		bullet.rigidbody.velocity = ( dir * DestroyBulletScript.rateOfMovement); //Fire it toward the target
				//print ("----SHOT [" + c + "]OUT!----");
				c++;
		}