- Home /
colliding bullets
hi i need help with colliding bullets when i set the speed to be to big they don't collide with the wall please help
Answer by Sebas · Feb 25, 2010 at 03:37 AM
The problem might be that through the high velocity of your bullet, the fixed frames in which your application is running are not enough to register your collision with the wall. In one fixed frame the bullet is in front of the wall and during the next fixed frame, the bullet already went straight through the wall. Everything that happens in between has no consequence for registering a collision.
One approach to avoid this problem is to use a raycast and build your logic of hitting the wall with the bullet on whether and where the raycast hit your wall.
There is one script on the Wiki which might of of help.
There is also some discussion about this issue in this forum thread. However, I believe just increasing collider size is not an ideal solution, because you will eventually be running into problems (literally!) when characters or other objects collide with your wall even though they are still at a distance to the actual rendered wall.
edit: A working example of a script for firing a bullet and using a raycast can be found in this forum thread.
the one in the fps tutorial just uses a raycast and no bullets i tried that but it did not look good
on the script Wiki is all that stuff really needed for colliding bullets
I personally haven't used the wiki script yet, but from looking at it, it seems this is required for not "missing" your wall with the bullet.
can you just say
var hit : RaycastHit; if(Physics.Raycast(transform.position,transform.TransformDerection(Vector3.forward,hit){ Destroy(gameObject); Instantiate(sparkPrefab,transform.position,transform.rotation); }
correct some syntax like a missing ) for your if statement and "TransformDirection" and try. I can't test anything since I am out of town for a few weeks. Sorry
Answer by Ashkan_gc · Feb 25, 2010 at 05:10 AM
you can increase the number of fixedUpdates. go to edit/project settings/physics and reduce the value of fixed delta time. this will have a performance penalty for you but you'll have more FixedUpdates so the collision will be registered. the best approach is to use raycasts as sebas said. unity checks for collisions in FixedUpdate and in your application the collision can not be registered because the velocity is too high and in a FixedUpdate the bullet is in one side of the wall and in the next FixedUpdate it is in another side. increasing the number of fixedUpdates can help but you can make sure to have all collisions registered with raycasts.
Your answer
Follow this Question
Related Questions
why Collider in tree Makes low fps 1 Answer
Terrain with lots of objects 1 Answer
Why would my floor suddenly disappear upon play? 1 Answer
bullets flying through enemy 1 Answer
FPS controller to not interact with certain colliders? 2 Answers