Bullet Physics v1

Hi everybody,

(First of all, this is not related to the Bullet physics engine! However I can’t seem to change the name of a thread…)

recently, i was trying to integrate a crossbow into my game. All working fine ( :slight_smile: ), only that when shooting my arrow/bolt at any mesh or terrain collider, the very fast (±100 m/s) rigidbody projectile would just pass right through. I’ve been working with unity for quite some years now, but this kind of bug keeps on occuring frequently, if not almost always.

I’ve done some research on the forums and found out, that most people avoid this problem using rayscasting or increasing the collider bounds of the projectile. Adding a larger collider was not an option for me, so I tried raycasting. Then again, I don’t get the ballistic flight curve/trajectory the projectile would actually follow. That was not an option either, so I came up with this. Since there seems to be no similar project on the forums (most of them just shoot in a straight line, thus ignoring gravity’s effets on the projectile):

Bullet Physics v1.0:

It took me about a day to set the whole thing up, test it and fix many bugs, but now it’s all working.

This system simulates the trajectory of a bullet or any fast moving small projectile using several raycasts along the flight curve of an actual rigidbody bullet. To make sure that there’s a delay between the moment you shoot and the impact, several rays are cast at regular intervals along the curve. All you need to do is enter the muzzle velocity of your gun, the muzzle and the gun itself. Your gun calls a function from the bullet physics script which then does all the dirty work for you.

So, what do you get from that? Correct bullet drop, bullet travel time and real troube hitting a moving target :stuck_out_tongue:

If you happen to have any questions, problems, bugs or whatever, feel free to contact me or ask right here on the forums.
PS: Read the READ ME file for further information on how to use.

Download:
Project: Click here
Package: Cick here

Really cool, i guess this would work as good for slowly moving stuff like bows as well?
Any chance you could put up a webplayer?

Sure, as I said, I originally designed it for a crossbow, which is basically just a bow with a stick attached :stuck_out_tongue:
Any kind of trajectory can be simulated: I even tried with speeds inferior to 20 m/s, which is kinda real slow…

What I forgot to mention:

1. There are two main scripts included! BulletPhysics.js and BulletPhysicsTraced.js, the traced one serves only for demonstration purposes. It’s good to set up your weapon by testing some parameters and to see how the projectile behaves/flies. You may replace it with BulletPhysics.js later on, this will remove the annoying marker balls and line renderer stuff.

2. There are two screenshots included to show you the trajectory decribed by your projectile/bullet. The traced script shows you the flight curve sing a line renderer, whereas the balls (markers) show the different raycasting sources. A ray is cast from one such point (steps and rays, see scripts) to the next one always after a specific amount of time, thereby simulating the bullet’s physical presence along these passages.

You may want to consider renaming this to Projectile Physics or similar, there’s a popular physics engine called Bullet Physics (www.bulletphysics.org) and this could cause confusion.

People looking for an integration of the Bullet engine would be interested and then leave when they see it’s not what they wanted, but also people who could be interested may think it’s an integration of the Bullet engine and so not bother looking.

Oh, didn’t know that engine… Okay, how the heck am I gonna change a thread name? …

I agree on this, i first thought it was a Unity integration of BulletPhysics engine.
Will pick this up for sure though, any chance of putting it on the asset store? Kind of convenient to have all assets saved on one place : )