- Home /
(Beginner) Adding a 2D Collider Randomly moves Player Off-screen when Game Starts!!
Hi Everyone!
I'm a Unity beginner and I am facing what is probably a simple problem, but I just can't seem to find the issue. My problem is that whenever I enable the 2D Box Colliders for the walls, my Player moves off-screen the moment I run the game.
As you can see below, I have three walls with Box Colliders and a player. When I run the game without the Box Colliders enabled, everything works as intended (except that the walls don't have colliders, of course).
However, when I run the game with the Box Colliders enabled, my player for some reason drops below the camera immediately as the game starts (refer to picture below).
Please note that I do not make any changes in my code between these screenshots. The only thing I do is starting/stopping the game and enabling/disabling the Box Colliders for the walls. I'm probably making a really dumb mistake, so please point out anything you see. Thank you so much! I have so much to learn.
The player teleports or anything? Could be that the player collider is too big or your code is doing that. Try check the player collider and disable any script to see if the problem persists.
Thank you for the reply. I actually just fixed it! I'm not sure why, but not using one of the default sprites and using my own image fixed the issue. Any idea why this could be the case?
Answer by Veenu-kun · Oct 03, 2021 at 05:54 AM
go to edit-->Project settings you will find checked boxes those are the layers, I think it indicates which gameObjects collides with another gameObjects
you must have given a layer to the walls. Uncheck the boxes of the wall's layer next to the player layer if you do that the player won't collide with the walls and the player won't jump of the camera
i apologize if the explanation is crap and that i answered it late i am new to unity as well. I started 3 months ago @marsh3476
Your answer
Follow this Question
Related Questions
Ignore sub-colliders for center of mass in Rigidbody2d? 1 Answer
OnTriggerExit2D not working on android (but works in editor) 0 Answers
Rigidbody2D alternating between TriggerEnter and TriggerExit? 1 Answer
HOW TO CALLBACK COLLIDER WITH NAME? 2 Answers
How to make certain rigidbody2d's not able to push other rigidbody2d's? 2 Answers