Hi.
I have added my 2D sprite player with two Box Collider 2D’s, one for the top part, and the other for the bottom, and a Rigidbody2D. Then there’s another empty object with a Box Collider 2D on the top as a ceiling to prevent my player from going above it. None of them are triggers. But my player seems to pass through the collider every time, after facing a very slight resistance. Then I’ve added a Rigidbody2D and turned off gravity , but still, nothing changes.
I’ve tried switching between Discrete and Continuous, and Static, Dynamic and Kinematic, but with no luck.
I just want to limit the movement of my player up to a certain level at the top, and the limiting object should be invisible. Any help in this matter would be greatly appreciated.
Note: The player position is controlled by a joystick using Transform.position, and an animation is added to the player rotation.
Take a step back and think about what the components are actually doing by adding them.
You added a Rigidbody2D because well physics but in the end the result is it setting the Transform position after it moves for whatever reason. Then you go and modify the Transform position yourself and stomp over what it’s doing. So do you want physics to control the position or do you?
In short, don’t modify the Transform if you’re using physics components. The Rigidbody2D is in charge of that so go via its API to control it indirectly. How you move it depends on you so choose between setting velocity, adding forces or using MovePosition/MoveRotation.