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 dsp4 · Oct 20, 2011 at 04:41 AM · collisioncollidermeshsweeptest

Mesh collider collision detection

I'm working on a 2D game that lets the user move physics enabled objects directly (using the mouse or touches). These GameObjects have colliders and rigidbody attached. For now, we're using boxes, but we plan on having more complex shapes, so we may need to use mesh colliders.

I need to prevent the user from dragging a shape into another one, while still being able to stick them one against the other. I tried using Rigidbody.MovePosition, directly changing the transform position and using AddForce, but all these methods cause varying levels of penetration between objects.

I had excellent results with SweepTest, only moving the object if SweepTest returned false, but SweepTest only works with primitive colliders, NOT with mesh colliders (even when enabling convex mode).

I've considered using MovePosition, then check if the collider fires the OnCollisionEnter callback, and then move back the object if it does, but the callback executes too late, it isn't called as soon as two objects collide, but only at the next FixedUpdate. It could be managed, but would be very cumbersome to work with.

It seems like the only reasonable solution is to combine primitive colliders to form complex shapes, but I'd like to make sure if there isn't another solution, if anyone would like to share it.

It would be great if there was some form of direct collision testing. Something like TestCollision(colliderA, colliderB), that would return true or false, and work with mesh colliders. A bit like SweepTest, but without the sweeping part.

Any pointer is super appreciated, Thanks!

Comment
Add comment · Show 3
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 syclamoth · Oct 20, 2011 at 04:45 AM 0
Share

Remember that mesh colliders only interact with primitive colliders, not other mesh colliders! (unless you mark them as convex). Could that be your problem?

avatar image dsp4 · Oct 20, 2011 at 05:19 AM 0
Share

Yes, they're all set as convex. They actually do collide. The problem arises when a user tries to forcefully drag one object into another, visually, they'll overlap. As soon as there is no more interaction from the user, the objects get out of each other, but it doesn't look too good, and sometimes, it creates explosive results, as the physics engine adds forces to try and separate the objects.

avatar image syclamoth · Oct 20, 2011 at 06:01 AM 0
Share

Well, if you use $$anonymous$$ovePosition along with OnCollision callbacks, you could set something up where it just doesn't move any further in that direction if it detects that it has run into something. A little hacky I know, but it might work for you.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Have a collider spit out any intersecting colliders to the closest next to them where there is no collision 0 Answers

player falling through walls of blocks in voxel game, collides with floor though. 0 Answers

Collision massively misplaced 0 Answers

I need help to mesh collision. 0 Answers

Edit WheelCollider's Axis, not the Mesh 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