Jump to content
  • Advertisement
Sign in to follow this  
Tset_Tsyung

UNITY - I'm slicing meshes, and then they explode...

This topic is 509 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all,

I have put a post about this in the UNITY forums... but then remember that this get more through put - I apologise for the duplicate post.

Basically, I have a catapult-smash-stuff game that I was trying to hack together for a "Game-A-Week" challenge.  However I'm having a random effect.

Please see this video (especially the end) to get a visual feel for what I'm on about.    



Basically this is the idea:

1) Boulder hits an object.

2) If boulder had enough velocity 'Split' the mesh once (random way).

2b) If other things are hitting each other with enough force (initial force is only provided by physics engine when boulder hits something - no addforce() code) then split (again in a random way).

This should be fine, however some of the 'slices' seem to be exploding off in random directions - and I have no idea how or why.

I'm telling the objects to 'split' from the OnCollisionEnter function - is this correct?

 

All replies greatly appreciated - and yes, that includes insults...

NB: noob, trying to learn about the physics engine, so please expect noobish mistakes.


P.S. The items being sliced are simple Cubes (with box colliders).

Howeve, after slicing they are no longer cubes and have mesh colliders to reflect this.  Also some of the triangles aren't showing on the sliced meshes (never had this problem before), could this have something to do with it? I thought this would just be a 'visual' issue...


P.S. The items being sliced are simple Cubes (with box colliders).

Howeve, after slicing they are no longer cubes and have mesh colliders to reflect this.  Also some of the triangles aren't showing on the sliced meshes (never had this problem before), could this have something to do with it? I thought this would just be a 'visual' issue...

Share this post


Link to post
Share on other sites
Advertisement

It happens because your collision overlaps.

When two physics objects intersect the engine solves it by ripping them apart, in the old days that would have merged the two objects.

What you need to do is either use very precise collision bounds or wait for some space between objects before turning on the collisions.

Metal Gear Rising faked physics to prevent the same problem you have. To do this use the direction from the split part to the center of the object. Use that to move the object so it's always moving outwards. Then once the object is clear from the mesh you can turn on the regular physics.

Share this post


Link to post
Share on other sites

Scouting Ninja,

You're a star, many thanks.

I though it was something like that.  It semed to lesson when I adjusted the width of the 'foundation' (think it was too thin and read that can throw off the physics). So now I just have to find a way to implement what you suggested... may as well repair the triangle code AND try using a hald-edge mesh system as was suggested.

This isn't going to make it into one of my "Game-A-Week" games for a while, lol.

 

Again, many thanks ;)

 

Er, how do I adjust the title to read that there has been a solution provided?

Share this post


Link to post
Share on other sites

Er, how do I adjust the title to read that there has been a solution provided?

You don't. Marking threads as SOLVED or similar isn't encouraged on these forums :) 

Share this post


Link to post
Share on other sites

@Scouting Ninja (or anyone else who reads this post)

Okay, so I've tried a few different methods of overcoming this, including what Scouting Ninja said (although need help with one of his methods, see below).
I've tried shitfing the new meshes away from each other (using the normal of the plane that sliced to work out direction) and even shrinking the objects a little by adjusting their scale.  However I'm still getting some exploding meshes, although less...

So I was thinking about Scouting Ninja's idea of 'waiting for space before turning the colliders back on', however if I do this with a non-kinematic rigidbody that uses gravity it'll fall through the world.  Turn it to kinematic with no gravity and it'll hang there in the game ruining the immersion.

PLUS, and this is the bit that I'm struggling with, I can't seem to find a utility in the UNITY physics API that allows me to get a list of all objects intersecting with a collider AT THE POINT OF CREATION.  OnTriggerEnter/Exit method of listing everything won't work because if there's an object already within the collider I don't believe that OnTriggerEnter will call.  I could try using OnTriggerStay, but I believe that requires at least 1 frame before checking what's "staying", and even though that's only 1 frame I'm concerned that it'll cause more issues as other moving objects may go in and out of the collider during this time.

Thoughts?!?!


P.S.

I wasn't too sure what you meant by using 'precise collision bounds.  Is that not what happens already when using mesh colliders?  I'm already using "Continuous Dynamic" in the rigidbodies... is there something else I can set to increase accuracy.

Edited by Tset_Tsyung

Share this post


Link to post
Share on other sites

So I was thinking about Scouting Ninja's idea of 'waiting for space before turning the colliders back on', however if I do this with a non-kinematic rigidbody that uses gravity it'll fall through the world.  Turn it to kinematic with no gravity and it'll hang there in the game ruining the immersion.

Metal gear used the hanging as part of the effect. The other thing to remember is that it is a game and the engines like the ones Unity use isn't correct at all; it has some noise in it to give a random result.

In Metal gear you will see the objects "hanging" and slowly moving while the player is slicing, then as time is set to normal the objects launch away.

 

Even with mesh collisions there is a small bias to prevent objects from clipping, you will need to move the bounds inside the object to have more accurate collisions.

Using the normals as you do, transition to a point where you are free then use the same normal to apply small physics force to "push" the object, causing it to lunch in a small ark. 

It isn't realistic, yet it is more interesting that actual physics.

 

 

Game physics is about interest not realism, if you want realism you will need to use a accurate physics engine; they are either boring or use too much computing power to be used in games.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!