Bullet Collision Issues

Right now my bullets are just spheres with rigid bodies (continuous-dynamic) attached to them. In order to shoot them I do:

1.Create the projectile using Instantiate 2. In Projectile.Start() do:

`this.GetComponent().AddForce(transform.forward * this.TrajectoryInformation.MuzzleVelocity * 500000 * Time.deltaTime);`

This moves the bullet quickly (which I want), but it sends other objects flying which I do not want. Also, I attempt to apply a decal at the location of the hit like so:

Vector3 hitPosition = new Vector3
        {
            x = collision.contacts[0].point.x,
            y = collision.contacts[0].point.y,
            z = collision.contacts[0].point.z
        };

        Quaternion rotation = Quaternion.Euler(collision.contacts[0].normal);

        //Create the decal (ie: bullet hole)
        GameObject decal = (GameObject)Instantiate(DecalPrefab, hitPosition, rotation);

        //Makes sure the decal stays on whatever it hit
        decal.transform.parent = collision.collider.transform;

This sometimes creates a decal but the decal is never rotated properly.

Any ideas on how to fix these things?

1 Answer

1

You say your decal sometimes works? Maby the bullet is so fast that the collision detection dont work. Have you tried to extrapolate the rigidbody?

If the bullet is intended to fly fast, maby it is better to do the collision detection with a ray, place the decal at the collided position and just use the model of the bullet for visuals.

Exactly. Unless you NEED to see the bullet fly (like it's pretty slow, which yours is not), use Raycast instead.

Thanks, I hadn't considered that rays would be a good idea for fast moving bullets. I don't suppose its feasible to also create a tracer/trail renderer? and what would the physics be like if I did this? Would I create a ray from the bullet start position (tip of gun) to the point where the camera is looking and then create some sort of explosion at the point of contact?