- Home /
Collision2D not detecting when playing is jumping
Hello,
I am designing a game in such a way that when a player collides with a coin, it gets destroyed. And quite frankly, that is working. However, whenever my player is jumping, the coins are acting as RigidBody objects (even though I don't have RigidBody attached to it), not letting the user pass through them, and not detecting collision at all. Here are some more information:
- Player has a RigidBody
- Coin do not have a RigidBody
- Coin has IsTrigger checked
- Yes, everything is 2D
- I am using a Polygon2D collider for the Player and the coins) (I also tried it with a box collider. Doesn't work)
- I have tried adding a RigidBody2D to my coins after doing some research. Doesn't help.
Any ideas? I will be REALLY thankful!
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("Collider with" + collision.tag);
if (collision.tag == "Player")
{
SoundManager.Instance.playSound(SoundManager.Instance.coinHit);
DestroyObject(gameObject);
}
}
Answer by Ramlock · Mar 26, 2018 at 03:59 AM
So you do collect the coin when walking, but collide with it and don't collect when jumping? If that's the case, then the script you provided has nothing to do with it. Your jump script is more likely to be the issue, for whatever reason.
Answer by Ziado4 · Mar 30, 2018 at 01:40 AM
@Ramlock You are right. Actually, when jumping I had a horizontal raycast which scans for colliders and prevents my player to move that direction if they find any. Even though isTrigger is on, the RayCast still detects the coin colliders and so won't let my player pass. Fixed this by telling my RayCast to ignore any objects (or colliders) of type Coin
The raycasts work independent of Triggers. They just need the object to have a collider.
Your answer
Follow this Question
Related Questions
using raycast to detect collision for 2D arkanoid/breakout game 0 Answers
Unity2D: How to make my player not walk through walls? 1 Answer
Collider Is Touching Layers is not working... 1 Answer
Wall checking not working correctly 2 Answers
How to change cards position when they collide to other gameObjects? 0 Answers