• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by rowanty · Aug 05, 2020 at 01:31 AM · rigidbody2dgravityboxcollider2d

Issues with rigidbody, boxcollider, and gravity in a 2d top down game

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. alt text
alt text

wth11.png (114.6 kB)
wth22.png (117.1 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rowanty · Aug 05, 2020 at 11:00 PM 0
Share

I have continued to troubleshoot the problem and haven't yet found the solution. However, I have uncovered an additional clue. After putting a constraint on the y-axis for my character in the rigidbody settings, the character does not fall, as would be expected. But as soon as I press left or right, the character rockets off in the direction pressed. For some reason, as long as the boxcollider is on, the velocity on my character's movement goes crazy, and I can only assume something in my script is putting a slight downward movement on my character as soon as the scene loads. The two effects are combining to make it appear as if he is falling due to gravity, but rather, he is rocketing off towards the bottom of the screen because of the downward push, and the incredible velocity.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rowanty · Aug 07, 2020 at 08:45 PM

For anybody having a similar problem, I think I've finally figured out what was wrong. After rebuilding the scene from scratch, I noticed that this problem only occurred again once I'd placed more than one boxcollider2D on the RoomParent object that I had created to hold my room template objects. (I was unaware at the time that you can't have more than one boxCollider2D on a given GameObject at a time) I can't explain why it works this way, perhaps someone more experienced than I can, but once I put a CompoundCollider2D on my object, everything started working nicely. Hopefully if anyone else out there runs into this problem, they can find it here! And if you feel you can elaborate or shed more light on my mistake I'd be happy to learn more!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

215 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RigidBody2d and BoxColider 2D not working 1 Answer

How to change the gravity scale of the rigidbody 2d back to it's default value after player lands to the ground from jump 0 Answers

How to prevent object pushing each other while rigibody is set to "Dynamic" ? 0 Answers

Rigidbody2D falls slowly with MovePosition? 1 Answer

How to make Smooth Gravity Transitions 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges