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 /
This question was closed Nov 10, 2013 at 12:21 PM by MadJohny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MadJohny · Nov 09, 2013 at 04:00 PM · physicsbugobjectsthrough

objects going through each other

Hi, I am making a beerpong game for a contest(theme is party), but I've been having alot of problems with physics, expecially objects going through each other:

https://dl.dropboxusercontent.com/u/151460612/beerpong/beerpong.html

as you can see cups go through each other, sometimes even the ball goes through the cups, how can I fix it? I think the problem is that the cups are too thin, the thing is, I don't know how to make 'em look good and easy to throw at but not as thin so things don't go through each other, any advice(except making the fixed timestep smaller)? thanks in advance

edit: the collision detection is already continuous dynamic, still doesn't work

edit2: seems that the ball is still going through some cups, I don't know how to fix this-.- the collision detection is already set to continuous dynamic and I'm using the DontGoThroughThings script, also I think the ball isn't that fast :/

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 Huacanacha · Nov 09, 2013 at 04:29 PM 0
Share

Unity's collision detection system is not accurate robust for small or fast moving objects. Check out the "don't go through things" script in the wiki for an alternative approach that works. Basically: Physics.Raycast from previous position to current position in each FixedUpdate.

avatar image MadJohny · Nov 09, 2013 at 04:38 PM 0
Share

already tried, didn't worked, btw look at the webplayer, everything isn't that fast, and everything goes through everything

3 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by robertbu · Nov 09, 2013 at 04:37 PM

The issue of the ball going through the cups and the issue of the cups going through each other different. The ball is related to the speed of movement. The ball moves in discrete movements and therefore can miss a collider. It is not a thickness issue. Given what I see in the game, the ball issue can be mitigated/fixed by reducing the the fixedTimeStep. Go to "Edit > Project Settings > Time" and reduce the 'Fixed Timestep' from the default value of 0.02 to 0.01.

As for the cups, in Unity, mesh colliders can only collide against each other if 1) they are marked as convex and 2) if they have less than 255 triangles. The problem is that, for your game, if you make the cups convex, the ball will not go into the cups. Your cup problem is not want I've ever solved, but I have a conjecture on how it might be solved.

  • Create a child game object to the cup

  • Create a simplified cup mesh

  • Create a mesh collider using your simplified mesh

  • Align the simplified mesh just inside the cup mesh

  • Mark the mesh as convex

  • Use Physics.IgnoreCollision() between the ball and all the simplified meshes.

Alternately you could attach a capsule collider to each cup. You will get some inpenetration, but you won't get the cups completely moving through each other.

http://docs.unity3d.com/Documentation/ScriptReference/Physics.IgnoreCollision.html

Comment
Add comment · Show 5 · 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 MadJohny · Nov 09, 2013 at 04:43 PM 0
Share

I just made a new mesh for the cup (to use as collider, 252 Tris, that should work right? :p phew that was close

avatar image MadJohny · Nov 09, 2013 at 04:53 PM 0
Share

Okay, I haven't made the Physics.IgnoreCollision step yet, but it was working fine with convex, until I noticed I couln't put the ball inside a cup, maybe because it's totally messing the collider? I don't know if it should be like this but I find it weirdalt text so on the left it's the collider with the convex option, and on the right it's not convex, will the last step fix that? I mean, I want to put the ball inside the cup, but the collider won't let me

convex.png (299.7 kB)
avatar image robertbu · Nov 09, 2013 at 04:55 PM 0
Share

A simplified mesh will not work by itself since you need to make it convex. If you mark it as convex, then the balls will not go into the cups. So you have to set it up as I've listed above...that is have two mesh colliders one on the parent one on the child. And again, this is just conjecture.

avatar image MadJohny · Nov 09, 2013 at 05:18 PM 0
Share

ah I get it now, so basically one mesh collider will collide with all the cups, and the other one will be used so the ball gets inside the cup, but ignores the convex one am I right?

avatar image MadJohny · Nov 09, 2013 at 05:25 PM 0
Share

Thanks :) that is working, upvoted and accepted

avatar image
0

Answer by Penfwasaurus · Nov 09, 2013 at 04:41 PM

Are you sure that the cup are not 'On Triggers' So they fall through anything with a collider?Plus you better check out all the colliders to see whether they are set up correctly, But yeah, also changing the fixed time step can help alot!

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 MadJohny · Nov 09, 2013 at 05:02 PM 0
Share

Yes I'm sure, and I already said I don't feel like changing fixed time step

avatar image
0

Answer by $$anonymous$$ · Nov 09, 2013 at 04:40 PM

The problem is that when the ball is moving too fast, the collisions of the cups and the ball have been skipped since all the collisions in your scene gets calculated in a phisics step. In order to avoid the missed collisions, you need to use raycasting. There is already a script in the Wiki Scripts page here. It uses Raycasting to determine if it will be collided, and will do some complex calculations to avoid clipping or any wired result.

 #pragma strict 
  
 var layerMask : LayerMask; //make sure we aren't in this layer
 var skinWidth : float = 0.1; //probably doesn't need to be changed 
 private var minimumExtent : float; 
 private var partialExtent : float; 
 private var sqrMinimumExtent : float; 
 private var previousPosition : Vector3; 
 private var myRigidbody : Rigidbody; 
 //initialize values 
 function Awake() { 
    myRigidbody = rigidbody; 
    previousPosition = myRigidbody.position; 
    minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z); 
    partialExtent = minimumExtent*(1.0 - skinWidth); 
    sqrMinimumExtent = minimumExtent*minimumExtent; 
 } 
  
 function FixedUpdate() { 
    //have we moved more than our minimum extent? 
    var movementThisStep : Vector3 = myRigidbody.position - previousPosition; 
    var movementSqrMagnitude : float = movementThisStep.sqrMagnitude;
    if (movementSqrMagnitude > sqrMinimumExtent) { 
       var movementMagnitude : float = Mathf.Sqrt(movementSqrMagnitude);
       var hitInfo : RaycastHit; 
       //check for obstructions we might have missed 
       if (Physics.Raycast(previousPosition, movementThisStep, hitInfo, movementMagnitude, layerMask.value)) 
          myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent; 
    } 
    previousPosition = myRigidbody.position; 
 }

Another case would be if your ball mesh is using a Mesh Collider, and if so I suggest replacing it with a sphere collider.

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 MadJohny · Nov 09, 2013 at 05:00 PM 0
Share

it's using a sphere collider(it's default unity sphere)

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Unity Gllitching Everything? 1 Answer

A node in a childnode? 1 Answer

Click and drag - Object go through other objects when dragging 1 Answer

Physics Lagspike? 1 Answer

Can you create characters only using unity? 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