- Home /
Objects Phasing in eachother (2d) please help
I my game, there is an enemy who wanders around, and if the player touches the collider of a game object that is a child of the enemy, that triggers the enemy to run at the player, and the same effect if you shoot the enemy, sometimes, it will hit you, deduce health, and step back, but other times, the player gets stuck inside the monster, it follows you, it doesn't deduce your health, and the only way to get out is to restart. here is the script for the monster's attack, the rest of code is just it's movement
void atacc() { if(Detect == true) { transform.position = Vector2.MoveTowards(transform.position, playerpos.position, speed * Time.deltaTime); }
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
player.health--;
transform.position = Vector2.MoveTowards(transform.position, playerpos.position, -speed * Time.deltaTime);
Detect = false;
patrol = true;
blast.canShoot = false;
hit = true;
StartCoroutine(Bite());
}
if (other.CompareTag("bullet"))
{
Destroy(other.gameObject);
BossHealth--;
if (Detect == false && patrol == true)
{
Detect = true;
patrol = false;
}
}
IEnumerator Bite()
{
yield return new WaitForSeconds(1f);
blast.canShoot = true;
hit = false;
}
if (other.CompareTag("Player") && Detect == true)
{
patrol = true;
Detect = false;
}
}
}
That right above this lie of text was something I tried, but it didn't work. The components of the player are a kinematic RB, and a polygon collider, the Boss only has a trigger collider, I also tried a second collider that would detect the collision, so the couldn't phase, but that doesn't work either.
Answer by The_GoldenDragon · Mar 20, 2020 at 12:31 AM
to anyone who reads this I think I solved it.
so game no longer broken... but they still phase :/