Bullets are phasing through my player character. How to make sure every bullet registers collision ?

This is the code I’m using to shoot bullets.

public Rigidbody projectile;
    public float speed = 200f;
    public float fireRate = 0.1f;
    private float nextFire = 0.0f;
	
    void Update() {
	 if (Time.time > nextFire) {
		 nextFire = Time.time + fireRate;
		 Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody;
		 instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
		}
    }

Your bullets are probably moving too fast, and on the first frame they are in front of the character and on the next they are on the other side.

A couple things you can do:

  1. Make the bullets move slower, which is the easiest thing you could do. You probably don’t want to do this because it will effect the speed of your game however.
  2. Make the bullets (or just their collider) bigger.
  3. Use a raycast from the bullet’s position on the previous frame to its position on the current frame and use that to check if there was any collision.

You can try setting the rigidbody Collision Detection setting of the bullet to Continuous Dynamic and the rigidbody Collision Detection setting of the player to Continuous. Alternatively if your bullets are moving so fast that they are basically instantaneous you can look into using Raycasts instead which would be a lot more efficient and effective.