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
2
Question by saldavonschwartz · Oct 15, 2013 at 08:29 AM · collisionrigidbodycollider

how could I break apart or unstick two intersecting rigid bodies

http://www.mediafire.com/download/x5zys2m44dj9rt5/test1.zip

(The camera script has a "Node" property which you can set to the cube or plane prefab)

alt text


I'm trying to do a classic: Be able to drag and drop rigid bodies around while having them collide and bounce with any other rigid bodies along the way. Of course, I'm also running into a classic issue: if I drag fast enough, I am able to intersect the body I'm dragging right into another body. Eventually PhysX might break them free from each other, but ideally I'd want the intersection to not happen in the first place. I'm moving the rigid body by doing rigid body.

         Vector3 newPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z));
         rigidbody.MovePosition(newPosition);

The suggestions that I've seen in the forum are usually along the lines of using the DragRigidBody script or the DragObject script. But neither feels right since they incur a noticeable lag between one dragging a finger / mouse to the desired position and the object following after the fact. Actually, considering the perceived velocity at which the object can be dragged, I don't see any difference between using those scripts vs the approach I showed above: moving directly to the new position, if done at a comparable velocity, won't result in bodies intersecting and getting stuck.

Anyway, so since the two drag scripts don't feel snappy enough, I was thinking what if I wait until after the bodies intersect and in OnCollisionEnter(Collision) for instance, apply some force to break them apart, given the contact points of the collision, or given some insight from inspecting both colliders involved in the collision?

Does anyone have any thoughts on what aspect(s) of the collision to base the direction and force to break the bodies apart?

This is what I mean by the bodies getting stuck together if I drag one of them too fast towards another:

alt text

These 2 planes are at the same z coordinate and are therefore intersecting. Eventually, depending on how the intersect, the physics engine will impart some force that separates them so they no longer intersect. But ideally they shouldn't be allowed to intersect in the first place.

screen shot 2013-10-15 at 1.42.19 am.png (3.7 kB)
16546-screen+shot+2013-10-15+at+2.05.46+am.png (11.0 kB)
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 Fattie · Oct 15, 2013 at 09:03 AM 0
Share

is this a 2.5D game? ortho camera?

you can't use planes (at all, ever, for any reason) in unity. make the colliders cubes (same length on all three dimensions)

avatar image Fattie · Oct 15, 2013 at 09:05 AM 0
Share

if you're asking what I think your'e asking, this question comes up a lot

http://answers.unity3d.com/questions/307540/is-it-possible-to-cast-a-ray-but-ignore-z-position.html

in 2.5D games, the COLLIDERS are often REALLY DEEP. so you might have enemies on layer 8 and heros on layer 7 and flying boulders on layer4 (I'm saying where the sprites are) but in fact the COLLIDERS of those things, would all be from like 2 to 20 in all cases, you know?

1 Reply

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

Answer by Fattie · Oct 15, 2013 at 08:37 AM

Having read all the comments, I believe the answer to your question is:

your colliders must be cubes.

As you say below, I literally mean "cubes" -- pretty much exactly the same length on all sides

Here is my demo project ... please grab the middle cube and move it.

http://www.filedropper.com/test2_4

NOTE -- the "cube" aspect has fixed your problem. (Please tick this answer :) ) But you are indeed on the fundamental limits of physX. Using my demo, try moving REALLY REALLY FAST. Of course, you will break it - but then - that would happen ion the real world, am I correct?

Hope it helps!


Regarding purely the issue of getting the "feel" you want (which is what i first thought you were asking.)

It is very difficult to do this. I think in this case you can and should "just move" the object at all times to exactly where the finger is. It will "smash out of the way" any other objects it encounters. You may have to additionally add "fling" .. when you let go, turn on the rigidbody again and give it a velocity based on it's recent finger-speed.

Comment
Add comment · Show 4 · 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 saldavonschwartz · Oct 15, 2013 at 09:39 AM 0
Share

So to recap:

  1. The key thing was not the meshes being planes (I re-tested and they can be 2d or 3d and it does not matter).

  2. what DOES $$anonymous$$ATTER is that the colliders be either cubes or at least not be too skinny in any one dimension (right now I'm using 10x5x10 and they work fine too.)

  3. As far as the feel, rigid body.$$anonymous$$ovePosition(thePositionOfThe$$anonymous$$ouseInTheCurrentFrame) feels snappy just fine.

  4. is$$anonymous$$inematic can be true or false, depending on whether you want the object you drag to also by affected by a force on collision with another object.

avatar image Fattie · Oct 15, 2013 at 09:44 AM 1
Share

(I'm fooling with your project demo now)

avatar image Fattie · Oct 15, 2013 at 09:57 AM 0
Share

I hope I have utterly answered your question - now I have to drink wine and eat lunch!

avatar image Fattie · Oct 15, 2013 at 09:58 AM 0
Share

just incidentally notice the excellent free "filedropper.com" service - amazing

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

15 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

Related Questions

Rigidbody stuck in colliders when moving and ricosheting. 0 Answers

OnCollisionEnter but have colliding object not move the object it collides with 1 Answer

handling collision with two objects of the same tag 1 Answer

Collisions between two rigidbody's and scripting collisions problem 2 Answers

Cannot get collision to do anything 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