Simulating realistic bullet physics.

I am developing a FPS game and I want to have bullets drop over distance and actually take time to travel but I don’t want to use rigidbodies because they’re too unreliable for detecting collisions.

In my head I have thought maybe I could take the angle that the weapon fires at and use that with an algorithm of some sort that will give me points along the trajectory that I can fire rays at different angles along with collision detection. I’m unsure however how I could accomplish this.

Could I have the rays fire at different points and time until there is a collision detected so the bullet doesn’t travel instantly but also not miss any collisions?

That’s basic calculus (which means it’s not really calculus.) Estimate the curve by doing lots of little straight lines. The official math term for this is the “shooting method.”

The “bullet” would be just a set of numbers – position, and x,y,z speed. Maybe spawn a bullet empty with that script. Each frame move the bullet forward and add gravity, then raycast from start to end. Then decide you want to do that in three steps/per frame (move 1/3rd, add 1/3 gravity, three times.)

If you do it adding gravity before the move (always a little too low,) then again adding after (always a little too high,) you bracket the real value, so can play with steps/frame until the error is tiny.

May as well add the wind, as long as you’re doing all that work.

Post is old, but somebody might find this useful! Just apply the script to a spawned GameObject, and everything else will be taken care of.

using UnityEngine;
using System.Collections;
           
            public class BulletPhysics : MonoBehaviour {
                public float gravity = -9.81f;
                public float velocity = 350;
                public float maxTime = 5f;
   
                private Vector3 origin; 
                private Vector3 cameraDir;
                private float increment = 0;
           
                void Start(){
                    origin = transform.position;
        cameraDir = Camera.main.transform.forward;
                }
           
                void FixedUpdate () {
                    //displacement = v0*t + 0.5at^2 + origin
                    //Debug.DrawLine (disp(increment), disp(increment + 0.02f), Color.red, 10);
                    RaycastHit hit;
           
                    if (Physics.Linecast(disp(increment), disp(increment + 0.02f), out hit)) {
                        Destroy (gameObject);
                    }
           
                    if (increment > maxTime)
                        Destroy (gameObject);
           
                    transform.position = disp (increment + 0.02f);
                    increment += 0.02f; //<--- fixedupdate time (value in Time settings)
                }
           
                Vector3 disp (float t){
                    Vector3 vel = velocity * cameraDir;
                    Vector3 disp = origin + vel * t - (playerDown * Mathf.Pow (t, 2) * gravity * 0.5f - Vector3.up * t);
                    return disp;
                }
            }