• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by WeirderChimp · Mar 17, 2014 at 09:10 AM · physicsraycastbullets

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

Comment

People who like this

0 Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image panbake · Mar 17, 2014 at 09:28 AM 0
Share

I have never implemented bullets like this, but I can think of a couple options for implementing them.

  1. 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.

  2. 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. Make sure you are not instantiating bullets, but instead just grabbing an available one from a pool. Hopefully some of this will point you in the right direction.

avatar image fafase · Mar 17, 2014 at 09:33 AM 1
Share

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.

avatar image CHPedersen · Mar 17, 2014 at 09:41 AM 1
Share

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.

1 Reply

  • Sort: 
avatar image
Best Answer

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).

Comment
whydoidoit
WeirderChimp
CriticalMammal
Jamster

People who like this

4 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bullet collision help 1 Answer

(C#) 2D Raycast wrong direction 0 Answers

Multiple raycasts in same fixedupdate 3 Answers

Raycast Car-Vehicle Physics 1 Answer

What does physics casting actually do? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges