- Home /
Help with bombs destroying colliders in different position from gameobject
I am currently creating a 2D infinite-runner style game. I have bombs that drop from bomb spawners as the player runs, and the bombs are supposed to destroy the pencilline that the player runs on, which is generated by a hand holding a pencil (tagged hand). However, right now when the bombs hit the ground, they destroy the colliders of part of the pencilline directly below the bomb, but the pencilline still appears there to the player, even though the player can fall through it. Directly to the left of where the bomb hits, part of the pencilline disappears, but the colliders still exist, allowing the player to appear to be hovering should they stand there.
Any help as to why this isn't working? I have a pancam class that moves at a constant pace, moving the camera. Currently, my bomb object has three animation states: bombidle, bombexplode, and bombdead. I am currently checking to see if the bomb is in the bombdead state before destroying the colliders and gameobjects in the circular area where the bomb hits.
My code:
using UnityEngine; using System.Collections;
public class Bomb : MonoBehaviour { //a holder for our Animator Animator anim; //a public float for the explosion radius public float explodeRadius = 1f; private GameObject bomb;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
bomb = GameObject.Find("bomb");
}
// Update is called once per frame
void Update()
{
if (anim.GetCurrentAnimatorStateInfo(0).IsName("bombdead"))
{
//destroy all the objects in a radius unless they are tagged Player or hand
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, explodeRadius);
foreach (Collider2D col in colliders)
{
if (col.tag != "Player" && col.tag != "hand" && col.tag != "navbar")
{
Destroy(col);
col.gameObject.SetActive(false);
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Code in void not executing 0 Answers
check if i'm collided with any objects of a certian tag? 4 Answers
Box and circle Collider doesn't work 1 Answer
RigidBody2D velocity speed difference between devices 0 Answers
Unity - halo doesn't work all the time 0 Answers