Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by wee_ooh · Jul 09, 2017 at 02:38 PM · 2d gamerigidbody2dcollision detection

I'm making a top-down action game. Should I use Rigidbody2D for collision even though I won't be using physics otherwise?

It seems like a waste to make everything into a physics object just to handle collision detection (basically I just don't want things passing though each other and detection for getting hit with player and enemy attacks), but on the other hand, from what I've been reading setting up collision detection without using RigidBody is much more complicated. Any suggestions?

Comment
Add comment · Show 2
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 Cherno · Jul 09, 2017 at 05:13 PM 0
Share

Well, since there is not CharacterController2D (unfortunately), you kind of have to use a RB2D if you don't want to write your own collision detection system (which is possible as well, and there are plenty of resource for it online). I'd suggest looking into using a RB2D and if it works for you without too much hassle then go with it.

avatar image EpsilonQoppa · Jul 09, 2017 at 08:39 PM 0
Share

@wee_ooh I updated the answer, sorry it took so long. Working on dinner.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by EpsilonQoppa · Jul 09, 2017 at 08:37 PM

So, I totally lied to you.

That being said, this still does not mean you need all of your objects to be physics based items.

The objects you want your character to not be able to pass through only need colliders.

However, you will need your character to have both a rigid body and a collider to trigger the oncollision event.

As to your question in the earlier comments, you will not need to code any type of system to keep your character from passing through objects. This is something colliders do intrinsically.

Having said that, you may want other things that will exist in large numbers, to enact a function when impacting an object without each of these instances undergoing physics updates.

In such cases, you can do something like this:

     Transform m_Transform;
     SphereCollider m_Collider;
 
     void Start () 
     {
         m_Transform = GetComponent<Transform>();
         m_Collider = GetComponent<SphereCollider>();
     }
     
     void Update () 
     {
         if (Physics.OverlapSphere(m_Transform.position, m_Collider.radius).Length <= 1)
             m_Transform.localPosition += (Vector3.forward * Time.deltaTime);
         else
             Explode();
     }

This will allow you to avoid calling fixed update every 0.02 seconds and still have things like projectiles impact targets.

Comment
Add comment · Show 2 · 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
avatar image wee_ooh · Jul 09, 2017 at 11:37 PM 0
Share

Haha no problem man, thanks for the update. I'll try the code you suggested. $$anonymous$$y objects with colliders attached aren't blocking each other, though, and I can't figure out why. Is there an option I have to enable (or disable)?

avatar image Cherno wee_ooh · Jul 10, 2017 at 12:56 AM 0
Share

Just having a collider is not enough. The object that is moving and should be stopped must have a non-kinematic RigidBody or equivalent (CharacterController, for example) as well. the involved colldiers can't be triggers either.

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.

Follow this Question

Answers Answers and Comments

74 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

Related Questions

How do I make Rigidbody2D movement smoother? 0 Answers

Instantiate new gameobjects on collision, keeping velocity, up to a cap 1 Answer

Object passes through collider even when isTrigger is turned off. 2 Answers

2D Sprite drifting down, otherwise passes through walls - how do I fix these issues? 0 Answers

Best way to rotate around a point with a RigidBody 2 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