- Home /
How To Really Do High Quality Bullet Physics like in AAA Titles
Hey All
I've made this thread because i cant find any other post that give a good high Quality way of making bullets. they just say use RayCast's and RigidBody's
It's not necessary to post about other stuff Eg Muzzle flash, recoil, zooming etc
i just want to know about the bullets and bullets physics
OK now for the actual question what is the best way of making bullets that Have bullet drop, You can SEE the bullets as they move through the air, good hit detection and lastly but most important Performance.
Using a bullet that has a rigid-body works well for the Bullet Drop and Seeing the bullet(tracing?) but bad on performance and VERY bad hit detection
Ray-cast's work well for Performance and Hit Detection
Is there a way to make a ray-cast that has bullet drop and you can see the bullet move.
/\/\/\/\/\/here's some examples(not my project or videos)
http://www.youtube.com/watch?v=GL_8_EKWnJY
Like In Battlefield 4
http://www.youtube.com/watch?v=oxZUNViLDUw (i would imagine this wouldn't isnt to good on performance)
thanks for viewing ~Scott
I have never implemented bullets like this, but I can think of a couple options for implementing them.
Use raycasting and apply "gravity" to the bullet's position in the Update method. With the right tuning this could give you what you're looking for.
Use a combination of raycasting and rigidbody, rigidbody for movement and raycasting to get the collisions.
Remember for fast moving objects like bullets you can do two collision checks with raycasting, one forward and one back, so that you're sure you catch every collision. Also bullets are really made for object pooling. $$anonymous$$ake sure you are not instantiating bullets, but ins$$anonymous$$d just grabbing an available one from a pool. Hopefully some of this will point you in the right direction.
You don't really need two raycasts, consider you store the previous position of the bullet, then next frame, you throw a linecast between from the previous position to the new position. If the linecast returns a hit, it means something was on the way and you can use the hit info to define whether it is a wall and then you ca add a texture on it or a soldier and you can hit him and add blood splatter and damage to the guy.
I like fafase's option a lot, because it also sounds like a great way to implement different material penetration capabilities on different kinds of ammunition or firearms. After fafase's test has revealed that a wall was in between the bullet and the enemy, you could evaluate the type of firearm used and ammunition and subtract some damage, cancel it altogether (the wall absorbed a weak shot) or maybe even add a random factor to the bullet's trajectory after having passed through a hard material.
Answer by fafase · Mar 17, 2014 at 09:17 AM
You have your answer in your question :).
You tell of Rigidbody fixing one part of your issue and raycast fixing the other part. SO what you need is both.
Use AddForce to shoot the bullet and let the engine handle the trajectory. You could add a trail renderer for a nice trailing effect. Make it real short so that it does not take too much on resources.
Finally, use a raycast to check on collision:
Vector3 prevPos;
void Start(){
prevPos = transform.position;
}
void Udpate(){
RaycastHit hit;
if(Physics.LineCast(prevPos, transform,position, out hit))
{
// hit.points is the impact point
// you can then check whether it is environment or else
}
prevPos = transform.position;
}
There are improvement to be done for efficiency like caching the transform, maybe comparing raycast and linecast (I read linecast being slower but easier to use here).
Your answer
![](https://koobas.hobune.stream/wayback/20220613140438im_/https://answers.unity.com/themes/thub/images/avi.jpg)