- Home /
Any way to ignore collision between rigidbodies and colliders/character controllers?
i use the script below in my enemy bullet prefab. The thing is that because of the collider and the character controller i use on the player, the bullet does twice the damage it should. Is there a way to prevent collision with either the capsule collider or the character controller?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyBullet : $$anonymous$$onoBehaviour {
public float damage = 10.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
collision.gameObject.GetComponent<PlayerStats>().player_health -= damage;
Destroy(gameObject);
Debug.Log("Player Damaged!");
}
else
{
Destroy(gameObject,2.0F);
}
}
}
Answer by RLin · Jul 22, 2018 at 03:43 PM
Make all character controllers exist on a different layer than the rigidbodies. Then, use the layer collision matrix to disable collisions between those two layers.
How do you make a layer for them though? They are not GameObjects but components of GameObjects!
Just change the layer for the GameObject that the component is attached to.
Actually i did using a much easier method. I just made the collider of the player a trigger and the problem is now solved! :D
Your answer
Follow this Question
Related Questions
How to change CC script to Rigidbody script 1 Answer
Collision on character controller (fps player) 0 Answers
C# Need Help converting from Rigidbody to Character Controller 0 Answers
How do I make a Character Controller NOT collide with Rigidbodies? 3 Answers
Collision detection from specific directions using rigid body character? 0 Answers