- Home /
Bullets colliding with Character Controller
Hi,
I'm not even sure the title is the issue but that's my best guess so far. I have a first person shooter where I'm using a character controller for my player and I can shoot bullets from the gun which have a SphereCollider set to Trigger. When I jump, if I shoot down, there a weird physics behavior which I can't understand. Here's a video demonstration.
I tried these things already to no avail: - disabling all the layer flags in physics so that player and bullets don't collide - using Physics.IgnoreCollisions (Player's character controller, bullets sphere collider) - I tried printing CharacterController.OnControllerColliderHit to the console, it shows floor, walls, etc. but bullets don't show up for some reason.
If I disable the sphere collider on bullets, then the behavior disappears, which means those sphere colliders (set to trigger) collide with something (I suspect my character controller) but I don't know how to disable this collision.
Help is appreciated!
Answer by Cuttlas-U · May 28, 2017 at 12:01 PM
hi; i think i had the same problem in my game ;
1 solution for this can be assigning different Layers to Bullet and player then go to Edit > Project Setting > Physics and disable the connection between the bullet and player layer , this way it will not Collide with the player collider;
Thanks for the reply, but as I already stated I tried disabling the physics flags and it doesn't solve the issue unfortunately.
Answer by melsy · Jun 15, 2017 at 03:02 PM
Are you by chance adding force to the bullets on impact? What does the code look like
No I'm not. The bullets are shot this way:
void Start()
{
GetComponent<Rigidbody> ().AddForce (transform.forward * bulletSpeed * 100);
}
void OnTriggerEnter(Collider _hitObject)
{
GetComponent<SphereCollider> ().enabled = false;
Instantiate(Object$$anonymous$$anager.instance.bulletImpactParticle, gameObject.transform.position, Quaternion.identity);
if (_hitObject.tag == "Enemy")
{
_hitObject.GetComponentInParent<Enemy> ().TakeDamage (bulletDamage);
}
Destroy (gameObject);
}