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?
Exactly. Unless you NEED to see the bullet fly (like it's pretty slow, which yours is not), use Raycast instead.
– DaveAThanks, 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?
– CommitteeWind