- Home /
OnCollisionEnter not working
So I am a fairly new user trying to make a game where you roll a ball to a portal. I made some lava that is supposed to make the player respawn when it touches the player. The player has a rigidbody2d and a box collider. The lava does not. I have a gameobject that contains all the lava in it.
The game is in 2D.
My Collision Script (attached to player) :
using UnityEngine; using UnityEngine.SceneManagement;
public class CharacterIsHarmed : MonoBehaviour {
public string SceneName;
public bool DebugCollide = false;
// Update is called once per frame
void Update(){
if (DebugCollide == true) {
SceneManager.LoadScene (SceneName);
DebugCollide = false;
}
}
void OnCollisionEnter (Collision col)
{
if (col.collider.name == "Lava")
{
DebugCollide = true;
}
}
}
The Gameobject containing the lava is named Lava.
After a bit of debugging thanks to @chiker and @KittenSnipes I found out that the collider was working but it would not say what i was colliding with.
Try printing something when you collide with anything, also make sure that your player has a collider and is not set to trigger, and that the lava has a collider and is not set to trigger
Answer by KittenSnipes · Mar 17, 2018 at 11:39 PM
@BunnyProductions I honestly think it is because you are mixing 3d and 2d. You gotta choose which one to use. I think you should use 3d so use a Rigidbody instead of a Rigidbody2d. If you want collisions to work everything will also have to have the same type of collider. So either they all have 3d collidera or they all have 2d. 2d objects can only interact with 2d physics and collisions and 3d objects can only interact with 3d physics and collisions.
@$$anonymous$$ittenSnipes I changed where it said OnCollisionEnter to a OnCollisionEnter2D and where it said Collision to Collision2D but its still not working.
Also I am making a 2D game
Your answer
Follow this Question
Related Questions
How not to penetrate the walls? 3 Answers
Character Collider doesn't collide with other Colliders 2 Answers
Help!Crash! FatalError"Callback registration failed kMaxCallback" 1 Answer
add camera collision without CharacterController 1 Answer
How to detect which side of a box collider was hit? (Top, Bottom, Right, Left) 2D game/ C# 3 Answers