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 ROM · Jun 20, 2010 at 02:08 PM · collisioncollidertriggeriphonetest

Detecting collisions between blocks?

Is there any other was to detect collisions between two objects other than this:

function OnTriggerEnter(collision : Collider) { 
   if(collision.gameObject.tag=="Player"){ 
      print("hit"); 
   } 
}

The problem with that is that it requires one of the objects to be a trigger meaning that physics do not apply to it. In the context of my application it means one object will pass through another which i don't really want.

Thanks in advance

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AnaRhisT · Jun 20, 2010 at 02:12 PM

function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag=="Player"){ 
print("hit");
 }
}

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html?from=BoxCollider

Description OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider

Comment
Add comment · Show 13 · 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 ROM · Jun 20, 2010 at 02:34 PM 0
Share

I actually looked at this earlier but it didn't seem to work. Is there something about the objects that I have to change? It just never says "hit"

avatar image AnaRhisT · Jun 20, 2010 at 02:35 PM 0
Share

$$anonymous$$aybe you don't have colliders/rigidbodies or they're triggered..

avatar image ROM · Jun 20, 2010 at 02:41 PM 0
Share

I'm using a sphere and box collider. The following code is applied to them:

function OnCollisionEnter(collision : Collision) { print("hit1"); if(collision.gameObject.tag=="Player"){ print("hit2"); } }

Neither hit1 or hit 2 are printer. its rather odd.

avatar image AnaRhisT · Jun 20, 2010 at 02:43 PM 0
Share

Check if they're trigged. if they're not, try to use a rigidbody.

avatar image ROM · Jun 20, 2010 at 02:52 PM 0
Share

How odd, I use rigidbody on one of them with the default settings and it works. I change the settings so the block doesn't move and it stops working. Hmmmmm...

Show more comments
avatar image
0

Answer by Nicolas 3D · Nov 30, 2012 at 04:53 PM

You can use OnTriggerenter, OnTriggerStay, OnTriggerExit, OnCollisionEnter, OnCollisionStay, OnCollisionExit :).

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
avatar image
0

Answer by AlexHogan · Sep 06, 2013 at 07:36 PM

Yes, this is working as described in the docs - at least one of the colliding objects must have a non-kinematic rigidbody to make the collision events happen.

Collider.OnCollisionEnter(Collision) Description OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

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

2 People are following this question.

avatar image avatar image

Related Questions

Using a trigger to align an object? 1 Answer

Collision returning an error 0 Answers

Box Collider Trigger Is True But Still Collide With Other Object 0 Answers

Detect a collision point, but allow pass through collider. 0 Answers

Detecting another object collision from another object script (2D) 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