Raycast seems to only sometimes work

So, I’m trying to use raycasting to detect bullet collisions, and it seems to be failing sometimes. I can’t find any kind of pattern to the failure either. Here’s the only code (other than member declarations) in my BulletPhysics script, which is the only script attached to the Bullet game object.

void FixedUpdate () {
		Vector2 rayPos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);

		collisionRay = new Ray(rayPos, velocity.normalized);
		
		if(Physics.Raycast(collisionRay, out hit, spd * Time.deltaTime, collLayer)) {
			hit.collider.gameObject.GetComponent<Enemy>().die();
			Destroy(gameObject);
		}
		
		gameObject.transform.Translate(velocity.x * (spd * Time.deltaTime), velocity.y * (spd * Time.deltaTime), 0);
	}

All the intended targets are in the correct collision layer and collLayer is set to that layer. I did notice that the number of false-negatives seems to go down if I increase the length of the raycast by increasing the value of spd, but I still get some. I have sphere colliders on both the bullet and enemy objects, and removing the collider from the bullet object didn’t seem to do anything.

Thanks.

Solved my own problem. It appears that raycasting is somewhat unreliable with a very small casting distance. Ironically I think the ray may be tunneling. I ended up increasing the casting distance by quite a bit, and checking the distance between the ray origin and the intersection point to see if they’re close enough to be colliding. So far no false-negatives. Thanks for the suggestions everyone.

Run this in void Update() rather than void LateUpdate, use LateUpdate for physics related actions.
also, this code is a bit complicated, but you could just check wether the bullet enters/touches the enemy collider, this can be done using

void OnCollisionEnter(collision col)

{

   if(col.collider.gameObject.tag == "enemy")

   {

  //do whatever

   }

}

Here is the script where I create enemies by instantiating them. After an enemy was created, I add a “Enemy” component to it and it allows me to call “Kill” method after I aim that enemy and click left mouse button. Enemy has “Enemy” layer assigned and that’s how it is being detected.
Everything happens in Update().
Drop this script onto your Player and assign all the public fields.
Let me know if it works.

using UnityEngine;
using System.Collections;

public class ShootSomeone : MonoBehaviour 
{

    public GameObject enemy;
    public Texture crosshair; //Thats just to see where I aim

    RaycastHit hit;
    private float rayDist = 500.0f; //How far to trace a ray

    void OnGUI()
    {
        GUI.DrawTexture(new Rect(Screen.width / 2, Screen.height / 2, 20, 20), crosshair);
    }
    void Update()
    {
        Aim(); //Checks the aiming
        InstantiateEnemies(); //creates enemies for me. u probably have different way
    }
    private void Aim()
    {
        Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); //Trace a ray from camera

        if (Physics.Raycast(ray, out hit, rayDist))
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (hit.collider.gameObject.layer == 8) //Enemy layer, they count from 1
                {
                    Shoot(hit.collider.gameObject); //I pass detected enemy gameobject
                }
            }
        }
    }
    private void Shoot(GameObject e)
    {
        e.SendMessage("Kill", SendMessageOptions.DontRequireReceiver); //Call KILL method on the Enemy
    }
    private void InstantiateEnemies() // This is just for demonstration purposes. I also instantiate the enemies
    {
        float randX = Random.Range(-5.0f, 5.0f);
        float randY = Random.Range(0.0f, 5.0f);
        float randZ = Random.Range(-5.0f, 5.0f);

        if(Input.GetMouseButtonDown(1))
        {
            Vector3 pos = new Vector3(randX, randY, randZ);
            GameObject _enemy = Instantiate(enemy, pos, Quaternion.identity) as GameObject;
            _enemy.AddComponent<Enemy>(); //Here I add class 'Enemy' to Enemy object as its new component
        }

    }

}
//Class that I add to the Enemy object after I create one
public class Enemy : MonoBehaviour
{

    public void Kill() //This is called remotely after I click left mouse button and aim on an enemy
    {
        Destroy(gameObject);
    }
}