- Home /
Object is not colliding with wall colliders
I'm currently having an issue with an object's collision. It is an "axe" that swings in front of the player, and has a trigger collider. I am checking collision with void OnTriggerEnter2D. It collides with all other objects just fine, but it is supposed collide with walls, making a sound and damaging certain walls. I can clearly see in the scene that it's collider is overlapping with the collider of the wall. It is also on the same layer as other player weapons that are not having this issue. It's z position is also zero. Trying to use other methods such as OnTriggerStay2D or OnCollisionEnter2D isn't working either. The list of contacts is empty when passing through a wall. It isn't a layer issue, it isn't a position issue, I am struggling to figure out what the problem could be. Anybody have any idea of a solution?
Here is the script, as I said it calls the other tagged collisions without an issue
void Start()
{
count = 0.0f;
startRot = transform.eulerAngles.z - 10;
startRotq = Quaternion.Euler(transform.rotation.x, transform.rotation.y, startRot);
desiredRot = transform.eulerAngles.z - 160;
desiredRotq = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, desiredRot);
}
void Update()
{
pushAngle = Quaternion.AngleAxis(transform.eulerAngles.z, Vector3.forward) * Vector3.right;
if (count < 1.0f)
{
count += 1.0f * Time.deltaTime * Swingspeed;
transform.rotation = Quaternion.Slerp(startRotq, desiredRotq, count);
}
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Eweapon" || col.gameObject.tag == "Wall" || col.gameObject.tag == "dWall")
{
int randomSound = Random.Range(0, objImpact.Length - 1);
GameObject newSource = Instantiate(sourceObj, transform.position, transform.rotation);
newSource.GetComponent<projectileSound>().PlaySound(objImpact[randomSound]);
}
if (col.gameObject.tag == "Eweapon")
{
Destroy(col.gameObject);
Targets--;
if (Targets <= 0)
Destroy(gameObject);
}
if (col.gameObject.tag == "Enemy")
{
col.GetComponent<Rigidbody2D>().AddForce(pushAngle * pushForce);
int randomSound = Random.Range(0, enemyImpact.Length - 1);
GameObject newSource = Instantiate(sourceObj, transform.position, transform.rotation);
newSource.GetComponent<projectileSound>().PlaySound(enemyImpact[randomSound]);
Targets--;
if (Targets <= 0)
Destroy(gameObject);
}
if (col.gameObject.tag == "dWall")
{
if (col.gameObject.GetComponent<DestructableWall>() != null)
{
col.gameObject.GetComponent<DestructableWall>().WallDamage(10);
}
else col.gameObject.GetComponentInParent<DestructableWall>().WallDamage(10);
}
}
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D & OnCollisionEnter2D Not Responding 1 Answer
Why do GameObjects need Rigidbodies to collide? 0 Answers
2D - Two objects, each having two trigger colliders - interacting 0 Answers
OnTriggerEnter and Exit seem to not be working 1 Answer
Detecting whether or not 2 objects are colliding in update() 2 Answers