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
1
Question by guitarstud101 · Oct 13, 2012 at 07:49 PM · physicstriggercollision detectioncontact

Obtaining Collision Information (contact points, etc.) WITHOUT affecting physics

Hi all -

I would like to obtain collision information (i.e. contact points, normals) for a collision between two colliders. I was happy to see that this info is already present in the Collision class, which I can access from the OnCollisionEnter() function. However, I need this information for "Trigger-like" objects that should not literally be colliding and bouncing off of each other.

The logical thing to do would be to make my objects Triggers and use the OnTriggerEnter() function. However, the OnTriggerFunction does not provide collision information like OnCollisionEnter does. (Not sure why this choice was made for the scripting API - I think it would have made more sense to give these two functions parallel behavior, but never mind.)

So it looks like the only way I can get the collision information I need is to use OnCollisionEnter(), but this only works when at least one of my objects is a NON-kinematic rigid body. So whenever it collides with another object it bounces off and flies away - not the behavior I need.

I have been trolling the community for a while now in search of an answer to this question, but no luck so far. http://forum.unity3d.com/threads/33091-SOLVED-Collision-detection-without-physics http://answers.unity3d.com/questions/9050/how-do-i-detect-a-collision-without-affecting-the.html http://answers.unity3d.com/questions/42933/how-to-find-the-point-of-contact-with-the-function.html http://answers.unity3d.com/questions/139560/how-to-get-the-collider-point.html http://answers.unity3d.com/questions/26053/how-to-figure-out-the-contact-point-of-ontriggeren.html http://answers.unity3d.com/questions/31810/collision-detection-without-a-rigidbody.html

Each of these "solutions" either makes the objects into Triggers (thereby denying me access to the information I need), making one of the rigidbodies Kinematic (which prevents OnCollisionEnter() from ever firing), or by using Physics.IgnoreCollision() (which also, obviously, prevents a collision from firing).

Am I SOL, or is there a way to get collision information from Trigger-like objects?

Thanks so much

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

4 Replies

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

Answer by Gray-33 · Nov 18, 2012 at 05:00 PM

Hi! In my project(sword fighting) I solvded this problem that way:

1)Attach a rigidbody to "weapon" gameobject. Set isKinematic = true.

2)Create empty gameobject "collider1" and parent it to "weapon".

3)Attach primitive collider to "collider1".

4)Attach rigigidbody to "collider1". Set all Constraints(FreezePosition and FreezeRotation) = true.

5)Attach FixedJoint to "collider1". Set ConnectedBody = "weapon".

6)Repeat (2)-(5) to create and customize compound collider for your "weapon" object.

"weapon" is object that you move by script or animation, multiple childrens collide[n] is needed to use as compound collider, because meshcollider doesn't give collision with other meshcollider. For example - I used 15 small boxcolliders to make a compound sword collider more realistic.

As a result you can read "collision", "contact point" and "normal" from OnCollisionEnter, but Physics doesn't move your colliders/objects. If you use Character motor, set "Use Fixed Update" = false to avoid "weapon" rigidbody move from hand, during your character walks.

Sorry for my English. Hope it helps you.

Best regards, Sergey Solodyagin.

Comment
Add comment · Show 1 · 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 guitarstud101 · Nov 18, 2012 at 08:41 PM 0
Share

PERFECT. That did the trick!

Thanks so much for your help. Still wish I could get collision info from a trigger though.... $$anonymous$$aybe in the revisions of 4.x....

avatar image
0

Answer by Loius · Oct 13, 2012 at 08:27 PM

You can set the "drag" and "angular drag" values of rigidbodies to 1.0 (or greater). These settings will slow the object's movement to zero at a rate based on how high the drag value is (higher drag = faster stopping). With an exceedingly high value, you'll only have the very faintest bit of a nudge when the two objects collide.

You can set drag in-game, so you could set drag to zero when the thing should move, then "really high" when you need it to stay in place.

If that isn't what you're looking for, what specific effect are you looking to get (billiards or something)? We might be able to give a workaround method for you.

Comment
Add comment · Show 1 · 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 guitarstud101 · Oct 13, 2012 at 09:13 PM 0
Share

Good suggestion - freezing the rigidbody with drag/angular drag solves part of the problem. However, the physics engine still wants to get the two overlapping colliders "out" of each other, so on the first frame it simply shoves the two colliders apart until they are no longer overlapping. After this point the drag setting keeps the objects from moving any further

avatar image
0

Answer by guitarstud101 · Oct 13, 2012 at 09:45 PM

Hey Loius thanks for the quick response.

I'll describe my particular situation below. However, even if there are better ways to get at the particular effect I'm trying to achieve, it seems to me that accessing collision information for Trigger-like meshes is an extremely useful thing to have anyway. The long list of previous posts is good evidence of this need: essentially a desire to do Intersection tests rather than Collision tests.


I'm playing around with lights and shadows, and want to have a shadow that "carves away" part of a spotlight (imagine a solar eclipse where the moon carves out a circular arc of the sun).

If this were purely a visual effect, I wouldn't be anywhere near collision detection and would probably just use a shader effect (or the stencil buffer, if I had access to it :) )

Instead (for good reason) I need the shadows and light themselves to be meshes. I am using the shadow volume technique to calculate a real-time shadow volume mesh, and I am planning to use a similar technique to calculate a "light volume" for the spotlight. But when the light and shadow volumes overlap, I'd like to calculate a new shadow volume mesh that is essentially "New Shadow Volume = Old Shadow Volume - Light Volume"

To do this I was trying to access contact points so I could do some procedural mesh "carving" (add the contact points to the shadow volume, then delete the points that were in the light volume).

I hope my explanation is somewhat clear - let me know if I need to be more specific!

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 tcz8 · Jul 31, 2018 at 03:28 PM

OnEnterTrigger doesnt have all the extra bells and whistles on purpose. When dealing with so many collisions that it is slows the game, you use triggers. They have other uses of course but this is why it was stripped down.

Personally, I would try this:

  1. Save the velocity and angular velocity

  2. On "OnEnterCollision" read all the info you need

  3. Restore the velocity and angular velocity

You are going to have to try a few things to figure out exactly when/where to save and restore the values but I would start with fixed update, if it doesnt work read this: https://docs.unity3d.com/Manual/ExecutionOrder.html

If anyone tries it let me know how it turned out!

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

12 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

Related Questions

OnTriggerEnter and OnTriggerStay often not registering 1 Answer

OnCollisionStay2D - why is the list of contacts is incomplete? 0 Answers

How to design an Archer Board Scoring System 1 Answer

OnTriggerEnter not called on rigidbody? 2 Answers

Character Controller Platformer - Hang on to ledges 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