First of all, forgive me as I am very new to all of this.
I have been following an online tutorial for a top-down zelda-like game. The player’s gameobject has a rigidbody2D with a body type of dynamic and a boxcollider2D. Since the game is top-down I need gravity turned off. I have turned y-axis gravity to 0 under edit > project settings > physics, as well as under edit > project settings > physics 2D. I have also set the rigidbody of the character to gravity 0 as well. I have even tried hard-coding a zero gravity into the character’s movement model, using Physics2D.gravity = Vector2.zero
, Physics2D.gravity = Vector3.zero
, Physics.gravity = Vector2.zero
, and Physics.gravity = Vector3.zero
. Even after all this, the character rockets towards the bottom of the screen when I hit the play button. The only thing that stops this behavior is turning off the boxcollider 2d, setting the boxcollider2d to “is trigger” or setting the rigidbody to kinematic. While all of these solutions make my movement model work fine, none are really useful since they prevent me from actually using colliders to restrict the player’s movement to within the scene. Does anybody have any idea what could be going on? Why is the boxcollider2D forcing my player’s gravity back on? Is there a way to stop this, or is there a Kinematic body type workaround? Attached are a couple images, the first shows my game running, the main character already having fell off the scene, the dynamic body type, and the zero gravity. The second image shows the game running, nothing has been changed except that the box collider has been turned off. As I said, similarly, if the box collider is set to “is trigger” or if the rigidbody is set to kinematic, the character stays on screen and my movement model works wonderfully. Unless there is a workaround however, I need a dynamic rigidbody, and some way to turn off the gravity even moreso than I already have.
Any help is greatly appreciated.