- Home /
How can I make the collider from the points ignore the ghost but not pacman?
Hi I am currently trying to make a pacman game for a school assignment. I have some trouble getting the ghost to ignore the white balls. any help? This is what I have in my ball script
void OnCollisionStay2D(Collision2D other)
{
if (other.gameObject.name == "ghost")
collider.enabled = false;
else if (other.gameObject.name == "Pacman")
Destroy (gameObject);
}
Answer by Sisso · Apr 24, 2014 at 09:02 PM
https://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
There is a layer matrix for physic and physic 2d
But won't I still have some problem with pacman not being able to touch them too? cause right now I have everything on the same layer right? But if I put pacman and the points in the same layer the ghost won't be able to touch anything?
3 layers one for each, and disable collision between ghost and points
You could have multiples problems here, one is ignore the collisions using layers, the other is how to correctly detect, like @robertbu said, use trigger in poits to detect the player
Answer by robertbu · Apr 24, 2014 at 09:30 PM
Set the collider to 'isTrigger' on the balls, and then use OnTriggerEnter(). The balls can check to see if it is the pacman or the ghost and act appropriately. Or depending on the structure of your code, the pacman can use the OnTriggerEnter() to delete the spheres.
Your answer
Follow this Question
Related Questions
Boxcoliders can't connect 1 Answer
Object size changing issue (w/ box collider) 1 Answer
BoxCollider2D error 1 Answer
BoxCollider2D is not working as expected 1 Answer
How can I combine many BoxCollider2D into one Collider? 2 Answers