I’m having an issue where a bullet will slow down and stop after a short period of time while snapping to surface normals of a sphere. Here is the code I am using:
function Update () {
transform.Translate(Vector3.forward * Time.deltaTime * bulletSpeed);
//transform.position += transform.forward * bulletSpeed * Time.deltaTime;
//Gets rotation object info
var globePos = new Vector3(0,0,0);
initCastDir = globePos - transform.position;
var hit: RaycastHit;
if (Physics.Raycast (transform.position, initCastDir, hit))
{
Debug.DrawRay (transform.position, initCastDir * 10, Color.blue);
transform.position = hit.point;
}
}
I can resolve this if I use this line in the raycast statement:
transform.rotation = Quaternion.FromToRotation (Vector3.up, hit.normal);
Unfortunately this forces the bullet to travel only upwards and makes it unable to rotate to the transform of the player.
Can anyone shed any light on this?