Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Jelly Mesh - Soft body style physics for 3D meshes

Discussion in 'Assets and Asset Store' started by mrsquare, Mar 3, 2014.

  1. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Select the Jelly Mesh object, and in the inspector you should see a field called 'Tag' (just below the object name). Set this to 'Untagged'.

    I suspect that you've copied a tagged Jelly Mesh object from the demo scene to another project and the tag info has been lost, but the Jelly Mesh gameobject is still referencing it.
     
  2. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Yes that works! Many thanks for your great support :)
     
    mrsquare likes this.
  3. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Hi, hopefully it would be ok to ask for some more advice again, let's say I take your blue blob sample and want to give lots of rotation on an axis, e.g. x axis, would I need to use the JellyMesh.AddTorque method to do this?

    I see in your sample code you use something like:
    Vector3 torqueVector = Vector3.zero;
    torqueVector.x = UnityEngine.Random.Range(0.0f, 0.0f);
    torqueVector.y = UnityEngine.Random.Range(0.0f, 0.0f);
    torqueVector.z = UnityEngine.Random.Range(0.0f, 0.0f);
    torqueVector.Normalize();
    m_JellyMesh.AddTorque(torqueVector * UnityEngine.Random.Range(m_MinTorqueForce, m_MaxTorqueForce), false);

    Should it be enough if I set torqueVector.x = something like 40.0f ? to make the mesh rotate on the x axis?
     
  4. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Hi, hopefully it would be ok to ask if you have seen my post? Any ideas anyone?
     
  5. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yep, exactly. You an just do eg.

    Code (csharp):
    1. GetComponent<JellyMesh>().AddTorque(new Vector3(40.0f, 0.0f, 0.0f), true);
    To make the object spin around the X axis.

    You'd have to experiment to find appropriate torque values as it'll be dependent on the mass of the physics bodies involved. Also, make sure that you haven't got 'Freeze Rotation X/Y/Z' set on the Jelly Mesh in the inspector.
     
    khos85 likes this.
  6. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Great, many thanks for your support. I had to use a very high number for my purposes but it works :)
     
  7. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,021
    Hi, I am using Jelly Mesh to great effect in my game but I cannot get the mesh to rotate as fast I would like..I'm using code:
    GetComponent<JellyMesh> ().AddTorque (new Vector3 (0.0f, 0.0f, (100000.0f *1000)), true);

    But no matter how many time I call this the mesh will only rotate at a certain speed as if some max rotation limit is reached (e.g. 1/2 a revolution for second), is there a drag setting or other setting I need to look to make rotate freely and as fast I would like? I cannot see what is blocking this yet. Thanks for any advice you can provide.
     
  8. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yeah, Unity has a max angular velocity limit, but you can change it on a per-rigid body basis. If you open up JellyMesh.cs and find the AddReferencePoint() function, you just need to do something like this:

    Code (csharp):
    1.  
    2.  Rigidbody newRigidBody = referencePointObject.AddComponent<Rigidbody>();
    3.  newRigidBody.maxAngularVelocity = 20;
    4.  
    (the default is 7, according to the tooltip, so just work upwards from there until you get a decent result)
     
  9. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,021
    Thanks for your hint! In my JellyMesh.cs I cannot seem to find the AddReferencePoint() you refer to? I see AttachPoint.. I am not sure where to locate this function. Also I cannot find maxAngularVelocity in any script yet, hmm strange, maybe I'm using an old version (I think I have 1.4.1)? Where else could I look/add the mentioned code?
     
  10. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hmm, it should definitely be there - that code hasn't changed for ages. Line 951:

    Code (csharp):
    1. /// <summary>
    2. // /Add a reference point - essentially just a rigidbody + circle collider - at the given
    3. /// position and with the given properties
    4. /// </summary>
    5. ReferencePoint AddReferencePoint(Vector3 position, float radius, bool addCollider)
    6. {
    7. ....
    8. }
    Email me your copy of JellyMesh.cs if you like and I can take a look at the version you're using.
     
  11. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,021
    Wow, after some time I found the function name AddReferencePoint, in the search tool (Mono editor) I has a space added, that caused the search not locate anything! Thanks for your help, once again :)
     
    mrsquare likes this.
  12. pjburnhill

    pjburnhill

    Joined:
    Mar 2, 2016
    Posts:
    27
    Hey @mrsquare, I can't get jellymesh to work with mesh colliders.. I've got a floor with a mesh collider and jelly object just falls through. Am I doing something wrong or does jellymesh not support mesh colliders?

    Edit: that is if the floor has a rigidbody too!
     
    Last edited: Sep 9, 2016
  13. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yeah, that should work fine. If you take a look at the demo scene then the floor is a mesh collider.

    In terms of physics behaviour, the Jelly Mesh code only uses standard Unity objects (the Jelly Mesh colliders are just sphere colliders + a standard 3D rigid body) so if stuff isn't colliding then it'll generally be a Unity-level issue rather than anything in the Jelly Mesh code. Definitely worth double checking all of your layer settings to make sure collisions are enabled between the Jelly Mesh layer and the floor, and maybe try swapping out your mesh collider's mesh for something really simple (eg. a cube) just to make sure it isn't an issue with the actual mesh itself.

    Re. your edit, you mean that it's only happening if the floor has a rigid body? ie. it's fine without?

    Feel free to email me a copy of your project if you like (or just a cut down version demonstrating the issue if you don't want to send the whole thing) and I can take a look. Address is in the readme file :)
     
  14. patrick-noten

    patrick-noten

    Joined:
    Sep 7, 2013
    Posts:
    12
    @mrsquare Hey there, I started to play around with the jelly mesh asset today and wanted to use that for the many characters I use in a game. These characters all use 2 materials to colour parts of the mesh, but when creating a jelly mesh and assigning the character mesh and pressing play, it would than change the mesh in the filter to "Jelly Mesh JellyMesh" where half of the character is no longer in the mesh, the submesh that used the 2e colour.

    The error it gives while this happens is: Failed setting triangles. Submesh is out of bounds. "UnityEngine.Mesh.SetTriangles(Int32[], Int32). -> JellyMesh: InitMesh() JellyMesh.cs:1567

    Using unity 5.3.5f.

    When using the mesh in a normal meshrenderer is renders just fine using both colours. and when just applied to the jelly mesh script and the filter it looks fine, untill I press play.
     
  15. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - have replied to your PM :)
     
  16. Lasse-Loepfe

    Lasse-Loepfe

    Joined:
    Mar 28, 2014
    Posts:
    25
    Hi,

    Jelly Mesh works perfectly for me when having the rotations locked. Howerver if I free them, the mesh deformation does not follow the rotation of my ball and penetrates the ground... is there a way to avoid this?
    Best
    Lasse
     
  17. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hi Lasse - would you be able to send me a video showing the issue? Or, better yet, if you don't mind uploading an example project + scene somewhere then I can take a look for myself. Thanks!
     
  18. Lasse-Loepfe

    Lasse-Loepfe

    Joined:
    Mar 28, 2014
    Posts:
    25
    Actually I could reproduce it in the demo-scene by just unlocking all rotation axis of the brown blob... using Unity 5.4.1f1, Windows 10
     
  19. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Cool, I'll check it out as soon as I can (apologies, I'm away on holiday until the start of next week so haven't got access to my PC just now)
     
  20. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    196
    Purchased this asset and am playing with it. Lots of fun. I'm wondering if it is possible to use this with animated meshes? I'm hoping to be able to import an animated mesh and then apply some of these jelly movements to it as well.

    Thanks!
     
  21. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hi - I'm afraid not, it only works with static meshes, not skinned ones. Having said that, I'm not too familiar with skinned meshes so I can't definitely say that it couldn't be made to work (if you were happy digging around in the code) but definitely won't work out-of-the-box :)
     
  22. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    120
    Hello @mrsquare,
    I purchased your asset Jelly Mesh few days ago and it works great!
    I had a question (actually 2), so I sent you an email. I am curious if you are still active - and what might be best way to reach you?

    Kind regards
     
  23. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry for the slow reply, have been away on holiday for the last week or so! Just to say that I've got your email, will try to respond properly ASAP :)
     
    sidtri2 and kreso like this.
  24. sidtri2

    sidtri2

    Joined:
    Jun 16, 2017
    Posts:
    1
    Hi Hugh,
    I just got and tried the asset. And forgive me if this is a question already answered in this forum (and I was just lazy to search n sort the results). But, what is the best way to make the character move and jump in a 3D SideScroller like setup. I can right now accomplish that with the following,

    myJellyMesh.AddForce(movement, true);
    myJellyMesh.AddForce(Vector3.up * jumpHeight, false);

    with of course reading from horizontal and vertical axes. But I'd rather not use AddForce() coz the force remains after I take my hand of the controls, and also the velocity is incremental. I used to use something like

    myRigidbody.MovePosition(myRigidbody.position + movement);

    to move a Rigidbody character before. So, any tip would be hugely appreciated.

    Thanks in advance,
    Sid.
     
  25. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    120
    Hello @mrsquare ,
    not sure if you got a chance to respond to my email but I haven't receive anything? Thank you for your time!
     
    Last edited: Aug 2, 2017
  26. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hi Sid,

    You should be able to use MovePosition still - just apply it to the central rigid body of the Jelly Mesh, eg.

    Code (csharp):
    1. GetComponent<JellyMesh>().CentralPoint.Body3D.MovePosition(x);
     
  27. Kagyu

    Kagyu

    Joined:
    Mar 5, 2016
    Posts:
    64
    Hello mrsquare,

    I planning purchasing Jelly Mesh but before I do that, let me know a little more about Jelly Mesh.
    Here are some questions.

    Q1. Can I fix designated vertices of Jelly Mesh to other non Jelly Mesh object?
    Q2. Can I set part of Jelly Mesh rigid bodies (that green sphere ones..) Kinematic?
    Q3. Can I set magnitude of deformation separately for each Jelly Mesh rigid bodies (that green sphere ones, again)?
    Q4. Can I build my own Jelly Mesh structure from scratch?
    Q5. Is Jelly Mesh compatible with Unity 2017?

    Thank you!
     
  28. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    120
    Hello Hugh,
    I am still using your fun plugin, for my project still in development. Thanks again for creating it!
    I can't reach you via email, also I tried PM on forums right now, and will try posting here as well.

    I have another question for you: I have a square jelly mesh. I am curious if you can think of a way to make it so that if the square is squished from top & bottom - it expands horizontally (keeping volume)?

    Please let me know your thoughts!

    Thanks!
    Kreso
     
  29. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey Kreso, sorry, not sure why your email didn't reach me. Good question - as I'm sure you've found, a Jelly Mesh won't behave like this naturally as it doesn't model the volume of an object, only the surface shape. I think you'd need to fake this effect - you could maybe try monitoring the total volume of the Jelly Mesh and work out a compression factor (ie. current volume/original volume). If that value gets less than zero, you scale up the spring lengths by the inverse of the value to allow the bodies to move further away from the centre. I've no idea how that would look in practice though (or whether the Unity physics simulation would remain stable)!
     
    Last edited: Apr 1, 2018
    kreso likes this.
  30. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    120
    Thank you so much for the idea. It certainly gives me some idea where to look. I appreciate it!!

    Kind regards,
    Kreso
     
  31. RdJpB

    RdJpB

    Joined:
    Oct 1, 2017
    Posts:
    2
    Hey mrsquare! Awesome plugin, I've been using it and it's really great.

    Questions:
    1. How would I go about making it so that Jelly meshes (i.e. spheres) would still be able to rotate in every axis (no rotation lock) when jumping and whatnot, but then have this constant tendency to slowly rotate themselves back to being upright (maybe after landing)?

    2. Is there some sort of LookAt function on your plugin? How can I make it so that a Jelly Mesh turns around to look at a specific game object?

    Let's imagine I have this sphere Jelly Mesh bouncing around like you have in the demo, but then I want it to stop, rotate itself back to the upright position and then turn around to look at some other object in the scene.
     
  32. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey,

    You should be able to get an interpolated look at vector using something like this:

    Code (csharp):
    1. Quaternion targetQuaterion = Quaternion.LookRotation(m_TargetObject.transform.position - transform.position);
    2. Quaternion interpolatedQuaternion = Quaternion.Slerp(transform.rotation, targetQuaterion, m_TurnSpeed * Time.deltaTime);
    And you can then apply this to the Jelly Mesh with

    Code (csharp):
    1. GetComponent<JellyMesh>.Rotate (interpolatedQuaternion.eulerAngles - this.transform.eulerAngles);
    However, the problem with using the Rotate function is that it just manually repositions the reference points without using physics forces, so it is possible to potentially move the bodies inside other objects if you rotate them too fast, which might cause the physics system to freak out.

    For that reason, it'd probably be safest to make it to a slow effect (ie. set a low m_TurnSpeed in the code above). Alternatively, you could try using .AddTorque (with the centreOnly argument set to true) instead of .Rotate (but I've not tried that) or else maybe modify the Jelly Mesh Rotate() function to call MoveRotation
    /MovePosition instead of setting the transform position/rotations directly.


    That should apply to both of your scenarios (ie. to rotate back upright, you are essentially just rotating towards an object that is in the direction that you want the Jelly Mesh to be facing)
     
  33. RdJpB

    RdJpB

    Joined:
    Oct 1, 2017
    Posts:
    2
    Sweet, I'll try it out, thanks! :)
     
  34. LeePerry

    LeePerry

    Joined:
    Aug 27, 2013
    Posts:
    5
    Hey, I'm in the early stages of thinking through a next project that might really use an asset like this.

    Is this expected to be supported for the forseeable future? You seem really responsive on here, which is a great sign.
     
  35. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yeah, absolutely, I'm more than happy to provide support for anyone that has bought it, just hit me up on here. I should get notifications if anyone replies to any of my threads, but occasionally they don't send for whatever reason so just shoot me a private message if I don't reply!
     
  36. Bodin

    Bodin

    Joined:
    Apr 19, 2017
    Posts:
    21
    Hi mrsquare,

    I got a problem. the child object I added to Attach point seem to me misplaced.
    please take a look in the picture below, when I added head part to attach point and press run, it's floating up in the air.
    Could you please let me know how to solve this?

    thanks in advance & best regards,
    Bodin

     
  37. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Just replied via email :)
     
  38. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,021
    Hi, is it possible to allow just a part of an object to use the jelly like behaviour? or only some vertices? Maybe in free mode and restrict the bounce on some colliders?
     
  39. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - not currently, but that should be relatively easy to do. If you had some may to tag the vertices then you could easily modify UpdateMesh() to just skip over any vertices that you didn't want to move.

    You might be able to achieve a similar-ish result by manually setting the spring joints on the Jelly Mesh to be really stiff after it has done the initial setup. The vertexes would still move a little bit in that situation, they wouldn't be totally fixed.
     
  40. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,021
    Cool, thanks, can jelly meshes work on child objects of a parent?
    The idea I have is to try use jelly mesh on my player's hat object, then if he runs or falls/jumps to make only the front part of the hat flutter around a bit.
    I have tried to implement this but am not getting very far, then hat does not like to follow my players head position very well.
     
  41. OutCyder

    OutCyder

    Joined:
    Mar 19, 2009
    Posts:
    2,178
    Hi, I see that the objects in the demo always keep their "head" up. Is it mandatory or can I have a completely physic driven object instead? I would like it to have a jelly cube to be kicked around.
     
  42. krehzzzy

    krehzzzy

    Joined:
    Dec 31, 2015
    Posts:
    12
    Hello! Would this work for something like a pole or sword that I want to bend on impact? For example, if you swing at a wall, the object will bend when it collides with the wall. Is this possible with your asset?

    Thanks
     
  43. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - I have the bodies in the demo set so that they can only rotate around the Z axis, but that is entirely optional so you can have them fall forwards/backwards/sideways if needed.
     
  44. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - mm, I think that behaviour might be a bit complex for the asset, unfortunately. I think the bodies wouldn't remain stable if you tried to do that, so you'd probably just get the shape exploding/oscillating wildly. It works best when the Jelly Mesh object is a standalone object.
     
  45. OutCyder

    OutCyder

    Joined:
    Mar 19, 2009
    Posts:
    2,178
    OK, thank you :)
     
  46. adscott1982

    adscott1982

    Joined:
    Mar 16, 2012
    Posts:
    21
    Hey mrsquare, I have been trying to use your extension to simulate a football, so something a lot more rigid than a beach ball, with far less deformation. However I cannot get it to work. In your testing have you been able to set up your sphere jellymesh to behave like a football?
     
  47. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - have you tried using the 'Attach Neighbors' option in the inspector? That should add some additional springs to make the whole structure a bit more rigid. I can't say that I've ever used it to make something so rigid though - the number of springs involved often makes the simulation a bit unstable if you set the stiffness too high, its definitely better suited to squishy objects!
     
  48. adscott1982

    adscott1982

    Joined:
    Mar 16, 2012
    Posts:
    21
    Thanks mrsquare - yes I did try that, unfortunately it didn't behave too well.

    Unfortunately the sphere physics out of the box in Unity aren't great in terms of spin / friction and behaving realistically on surfaces. I think it may be due to the tiny contact point between a sphere and a surface. I was hoping using a softbody might introduce more contact area between the sphere and the surface, and also solve behaviours where it is in contact with multiple surfaces simultaneously.

    I suppose I could try and spin my own, but I am not sure it would be any superior to what you provide. It's a bit frustrating.
     
  49. tosief1

    tosief1

    Joined:
    Jan 7, 2019
    Posts:
    1
    is there any user manual how to use it ?
    if not you should make one
     
  50. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
unityunity