- Home /
Bullet Collision Simulation?
Hey I made a script where my FPS controller shoots a small bullet from an empty parented right in front of the camera... essentially sending a small bullet out as if in an FPS controller. The problem is that that collisions are quirky and fifty percent of the time the bullet passes right through the target without affecting it. I know how to make a script that adds force away from the camera with RayCastHit, but this is not realistic because no matter where i click the object it always apples force away from the player, where as a real bullet would push it where ever it hits the mesh and apply torque as well... etc. How can I simulate this "bullet collision" with a raycasthit or solve the collider problem?
Answer by Loius · Nov 16, 2010 at 03:23 AM
Does AddForceAtPosition help? It should be compatible with raycast-bullets and still give the torque component you're looking for.
If you need physical bullets, look up DontGoThroughThings (a community script on the wiki I believe), or use raycasts each frame to see if the bullet has skipped something it shouldn't have.
Thanks for the script. I noticed the script checks only for objects in the specified layer. Does this imply I will get performance issues if I just spam the world with objects with the layer?
Answer by Mike 12 · Nov 16, 2010 at 03:57 AM
You said "as if in an FPS controller"? What do you mean by that? The FPS controller, doesn't really use the PhysX engine to detect collisions. You could just try not to attach a character controller to your bullets if that's what you're trying to do.
Maybe you should try creating an empty game object with a collider and rigidbody attached to it and send it off from the gun that way.
I've had a similar experience with some bullet objects of my own, and they too would go through other game objects and the collisions were never detected. But, since I wasn't using the built-in Physics engine in Unity to do all the work and was performing my own calculations, I ended up using the RaycastHit class for my work.
Yet, like I said earlier, if you just simply create your own game object with a collider and rigidbody, then right after you've set the velocity for the object the object should fly through the environment and collide however you want it to.
Your answer
Follow this Question
Related Questions
Raycast bullet collision problem 1 Answer
How can I change this script? 0 Answers
Collision Detection between certain objects 2 Answers
Instantiated bullets hitting GameObjects? 4 Answers
Destroy Bullet On Collision? 1 Answer