Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 drodrii · Mar 06, 2014 at 06:11 PM · gameobjectrigidbodycollisiondetection

2D Object Collision - How To?

Hello everyone, I'll go straight to the point.

I've created 2 objects. ObjectA & ObjectB.

One is static(ObjectB) and one(ObjectA) has a script to go forward(towards ObjectB).

I want to add a Debug.Log when ObjectA collides(enters bounding box) of ObjectB.

How can I Implement this? I know I can do this w/RigidBody and wo/Physics.

Where my question is going is, my gameplay is a 2D Zeldaish Moving world.

What would be your best approach to do the Debug.Log. and How?

Thanks for your time and answers!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · Mar 06, 2014 at 06:37 PM

The solution is triggers!

This is a key part of the docs to read: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html

Add colliders to both objects, and a rigid body to Object A (at least 1 object involved has to have a rigid body for triggers to work).

If you don't want Object A to move under physics, set its rigid body to 'kinematic' - that means it exists in the physics world but you just move it via script rather than using proper physics.

Set Object B's collider to be a trigger (its in the properties). This will mean that when object A enters the collider it will call 'OnTriggerEnter' on any scripts on either object.

That should do it for the scenario you describe. It's a little different if you want objects to be bouncing around under physics instead (you use the OnCollisionEnter function instead) but the same principle applies.

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 drodrii · Mar 07, 2014 at 03:28 AM 0
Share

@wibble82 Is there any difference if Im doing this on 2D? I tried adding box collider and then rigidBody2D but I had a warning "Can't add component 'Rigidbody2D' to Bullet because it conflicts with the existing 'BoxCollider' derived component!" also if its possible, how can I tell ObjectB that ObjectA collided with it?(as in if added another Object, how could I deter$$anonymous$$e which Object collided with B?)

avatar image JNSVS · Mar 13, 2014 at 08:49 AM 0
Share

Add Physics2D Box colliders. And for triggers there is a seperate set of functions for 2D

avatar image
0

Answer by Max_power1965 · May 24, 2020 at 03:48 PM

I also had really a lot of problems when configuring the collision between game objects. After years I wrote every tips in this article https://gamedevelopertips.com/unity-collision-detection-2d/, I'm sure it'll be helpful if you want to set up properly you collider/triggers property.

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.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Creating a teleportation gun 1 Answer

Horizontal gravity on One gameobject 2 Answers

Game objects sliding when frozen z-axis? 0 Answers

instantiate a gameobject or rigidbody? 1 Answer

How to determine the direction of an object to the player. 1 Answer


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