Search Unity

Jelly Sprites - Soft body sprite physics system

Discussion in 'Assets and Asset Store' started by mrsquare, Dec 5, 2013.

  1. marpione

    marpione

    Joined:
    Apr 16, 2016
    Posts:
    26
    Hello. First of all, this looks like a great asset. However, I'm wondering is it possible to set amount of time for the sprite to get back to his regular shape after being compressed or squeezed.
     
    crazy_genius likes this.
  2. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - you can't set an explicit time I'm afraid. Everything is spring driven (using native Unity physics springs) so you have to use the stiffness and damping values to control how quickly/smoothly the bodies return to their natural position. It requires a bit of balance but looks more natural than just a fixed time interpolation.
     
  3. marpione

    marpione

    Joined:
    Apr 16, 2016
    Posts:
    26
    I see the object I'm going for is not jelly actually it's flexible more like a box you squeeze and it stays like that and over time takes back it's original shape. Are you using spring joints if so maybe I can play with it to have what I need?
     
  4. Bailey4864

    Bailey4864

    Joined:
    Jan 9, 2018
    Posts:
    1
    Hi is there away to start the effect without a collision? I have a jelly object thats static and I just want it to wobble slightly on its own.

    Have I downloaded the correct package?
    I've had a good play with the configuration but cant seem to get the desired effect. Am I missing a setting?
     
  5. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yep, there is an AddForce() function in the code that you can use to add forces manually.
     
  6. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    Hi, the jellysprite does not contain a definition for (transform) what would I use instead
     
  7. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    I don't really understand - a Jelly Sprite is a just a standard monobehavior component attached to a gameobject, which means that you can call

    Code (csharp):
    1. component.transform
    to access the gameobject's transform, as you would from any component.
     
  8. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    I’m having some troubles, would I be able to get some help?
     

    Attached Files:

  9. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - try this:

    Code (csharp):
    1.  
    2. if (col.ReferencePoint.transform.CompareTag("Player"))
    3.             col.ReferencePoint.ParentJellySprite.GetComponent<JellySprite>().SetPosition(spawnPoint.position);
    4.  
     
  10. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    I’m a having a little trouble with the script you sent me
     

    Attached Files:

  11. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Ah, sorry - you need to pass through 'false' as a second argument, ie.

    Code (csharp):
    1.  
    2. if (col.ReferencePoint.transform.CompareTag("Player"))
    3.     col.ReferencePoint.ParentJellySprite.GetComponent<JellySprite>().SetPosition(spawnPoint.position, false);
    4.  
     
  12. ResiduelGG

    ResiduelGG

    Joined:
    Sep 27, 2017
    Posts:
    4
    Hey!

    I have just purchased this asset pack. Just tried to test thing out and see how it works in blank project and for some reason Jelly Sprite Reference Point with all of the colliders is created outside of the main Jelly Sprite GameObject. All i did is was - created Jelly Sprite GameObject and added demo sprite. Here is the screenshots of the issue:

    bug1.png bug2.png

    As You can see Jelly Sprite Reference Point is not inside the Jelly Sprite GameObject. My unity version is 2018.2.18f1. Can be related to newer vesion that i use, but would be cool to get this resolved as i think this is basic thing. Have not yet had time to look into code and try to resolve this myself.

    Awaiting reply, hope there is a quick fix for this.

    Thanks! Cant wait to use this asset for my project ;)
     
  13. ResiduelGG

    ResiduelGG

    Joined:
    Sep 27, 2017
    Posts:
    4
    Did some digging around and JellySprite script have public field m_ReferencePointParent, but it is never used as an input as it is not present in JellySpriteEditor script - instead new game object is created to contain all of the points:

    Code (CSharp):
    1. m_ReferencePointParent = new GameObject();
    2. m_ReferencePointParent.name = this.name + " Reference Points";
    So it looks like this was done intentionally.

    Tried assigning points to be children of main JellySprite GameObject, but that completely broke the functionality. Seems that there was reason why Reference Points is in the separate object. Can it be done so everything is neatly packed in the one GameObject?

    Another thing that i am sure is intended, but looks weird is that when i select both main game object as well generated Reference Point Parent it remains centered (why pints probably are not part of main GameObject) and streaches the Parent container like in the image:

    bug3.png

    Functionally everything seems wo work fine, just wondering is it possible to pack everything to one GameObject and it would be moving with everything else e.t.c.

    Because in initial demo whihc was created like 5 years ago, everything seems to be child of the main GameObject was hoping for same functionality.
     
    FineAllDay likes this.
  14. FineAllDay

    FineAllDay

    Joined:
    Jun 14, 2016
    Posts:
    11
    Edited:

    I found out that when I change the Spring stiffness to 6 and more the overlapping sprite issue disappear, but the sprite is not as soft... It would be nice to have the possibility to have a very soft body that follow the colliders...

    ////////////////////////////////////
    Hi!

    I have purchased your plugin and I have a little problem. The bottom part of the sprite does not deform to follow the colliders. This is causing an overlapping of the floor sprite and the jelly sprite. I use the last version of Unity: 2018.3.0f2

    As it is, it not possible for me to use the plug-in because of this issue.

    I also get this warning: (when I connect one anchor)
    Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
    UnityEngine.Transform:set_parent(Transform)
    JellySprite:CalculateInitialOffsets() (at Assets/JellySprites/Scripts/JellySprite.cs:531)
    JellySprite:Start() (at Assets/JellySprites/Scripts/JellySprite.cs:479)

    Thanks!
     
    Last edited: Dec 30, 2018
  15. Justin-Whitney

    Justin-Whitney

    Joined:
    Jun 10, 2013
    Posts:
    6
    Do you have a script where I can make the Jelly sprite the child of another sprite to where it will have the same movements and behaviors of the parent sprite or sprite-mesh but will still have its bouncy physics?
     
  16. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - your best bet is probably to keep the two objects separate (ie. don't make the Jelly Sprite a child to the other one) but instead set the Jelly Sprite to be kinematic and then manually position it (JellySprite.SetPosition()) so that it tracks the position of the parent object.
     
    Justin-Whitney likes this.
  17. Justin-Whitney

    Justin-Whitney

    Joined:
    Jun 10, 2013
    Posts:
    6
    Thanks, Ill give it a try! Love the asset by the way!
     
  18. Justin-Whitney

    Justin-Whitney

    Joined:
    Jun 10, 2013
    Posts:
    6
    Code (CSharp):
    1. public class JellyAttachment : MonoBehaviour
    2. {
    3.     public GameObject m_ManualMesh;
    4.     Vector3 m_ManualMeshLocation;
    5.     JellySprite m_JellySprite;
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         m_ManualMeshLocation = m_ManualMesh.transform.localPosition;
    10.         m_JellySprite = GetComponent<JellySprite>();
    11.         GetComponent<JellySprite>().SetPosition(m_ManualMeshLocation, false);
    12.     }
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         m_ManualMesh.transform.localPosition = m_ManualMeshLocation;
    17.         m_JellySprite.SetPosition(m_ManualMeshLocation, false);
    18.     }
    19. }
    This is what i was trying to do in a new script like your JellySpriteAnimator script, but I'm afraid I don't know what I'm doing, any tips for getting the jelly sprite to move and rotate with the public game object linked with the component? or should i be editing the JellySprite.SetPosition in the base script?
     
  19. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    That's nearly correct, you just need to ensure that you're setting the central point to be kinematic (you can also just do that in the inspector if you want) and also set the rotation (if you want it to rotate too). You also need to update the position/rotation every frame if you want it to continue tracking the other object. An updated/simplified version would be:

    Code (csharp):
    1.  public class JellyAttachment : MonoBehaviour
    2. {
    3.     public GameObject m_ManualMesh;
    4.     JellySprite m_JellySprite;
    5.  
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         m_JellySprite = GetComponent<JellySprite>();
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         m_JellySprite.CentralPoint.Body2D.isKinematic = true;
    16.         m_JellySprite.SetPosition(m_ManualMesh.transform.position, false);
    17.         m_JellySprite.CentralPoint.Body2D.transform.eulerAngles = m_ManualMesh.transform.eulerAngles;
    18.     }
    19. }

    I gave that a try in the demo scene and it seems to do the trick.[/QUOTE]
     
    tigerss likes this.
  20. Justin-Whitney

    Justin-Whitney

    Joined:
    Jun 10, 2013
    Posts:
    6
    [/QUOTE]That seems to have done the trick! thank you!
     
    tigerss likes this.
  21. tigerss

    tigerss

    Joined:
    Oct 11, 2015
    Posts:
    20
    Hi,

    Would love to achieve this effect


    Right now I'm tweaking Spring Stiffness, Spring Dumping, Collider Radius, Collider Scale, Body Config (Circle)
    But in the game from the video, the player is not very wobbly, the colliders seem to get at rest fast. It's more gummy than jelly I think

    What do you think?
     
  22. IMTAL1741

    IMTAL1741

    Joined:
    Feb 21, 2019
    Posts:
    1
    Hi, how can I make the sprite deform like the collider. Ie to sprite is not combined with the wall and to look realistic?


    Clip2net_190313221817.png
     
  23. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    You won't be able to do that with Jelly Sprites I'm afraid, you'd need to use a full 2D soft body physics simulation if you wanted the object to accurately wrap around the wall. There was a unity asset called Jello Physics that might be of use (I don't think its supported any longer, although its free to download from github)
     
  24. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Does your Googly Eyes asset work with 3d assets or 2d only? Thx!
     
  25. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    It's 2D only, I'm afraid!
     
  26. Supervitux

    Supervitux

    Joined:
    Nov 16, 2019
    Posts:
    2
    Hi mrsquare,

    First of all thank you for creating this asset it helped me out a lot! Now, on collision of JellySprite A with JellySprite B, I try to obtain change a variable, however I get a NullReferenceException.
    Code (CSharp):
    1.  
    2. // This is executed in JellySprite A
    3. private void OnJellyCollisionEnter2D(JellySprite.JellyCollision2D collision)
    4.     {
    5.                 var my_script_in_B = collision.Collision2D.gameObject.GetComponent<my_script_in_B>();
    6.                 my_script_in_B.variable_in_B = 1f;
    7.         }
    If I check collision.Collision2D.gameObject.name I understand that A collided with Reference Point 14. So I see I cannot get my component from collision.Collision2D.gameObject, but I am not sure where I can get it from.
    I am sorry, if that is just due to my inexperience as a beginner, but I tried out a lot and would be happy about any kind of help.

    kind regards

    Supervitux
     
  27. Supervitux

    Supervitux

    Joined:
    Nov 16, 2019
    Posts:
    2
    Hi again,

    I solved my problem with this work around

    Code (CSharp):
    1.         JellySpriteReferencePoint test = collision.Collision2D.gameObject.GetComponent<JellySpriteReferencePoint>();
    2.         GameObject parent = test.ParentJellySprite;
    3.         var my_script_in_B = parent.GetComponent<Particle>();
     
    mrsquare likes this.
  28. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Hi, is there a way to set scale instead of multiplying it?
     
  29. Jimbo_Slice

    Jimbo_Slice

    Joined:
    Oct 1, 2015
    Posts:
    44
    Been having the same issue here. I am using the Sprites/Diffuse shader for my gameObject but on line 79 of UnityJellySprite.cs you are initializing the material with the Sprites/Default shader.

    For my game I can just change this line of code but you might want to cache the shader the user has selected and use it in the future release of the plugin :)
     
  30. SDRob

    SDRob

    Joined:
    Oct 4, 2018
    Posts:
    2
    I was following the steps of the YouTube tutorial but it seems like my sprite will not squash and stretch like its colliders are.

    Here is a gif of what it looks like:
    JellySprites (1).gif
     
  31. RubensRayo

    RubensRayo

    Joined:
    Mar 7, 2016
    Posts:
    1
    [/QUOTE]


    Hi, I'm trying to do this but it's failing me at some point.
    Do you add this script to your own jelly_sprite or the object to follow? Because in both cases it gives me a NullReferenceException:

    Thank you
     
  32. Kayumus

    Kayumus

    Joined:
    Jul 21, 2020
    Posts:
    15
    I have a question about your asset.

    I need to slice sprite by 2x2, 3x3, 4x4 and 5x5 in script which means by coding.
    Do you think your asset can solve my problem?
    If I buy your asset, can your asset solve my problem?

    See the example pictures below: It explains my problem:

    turtle.png

    grid-2x2.png grid-3x3.png grid-4x4.png grid-5x5.png
     
  33. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hello mrsquare,

    Is there a way to assign "svg" format sprites to Jelly? I tried but it is not working right away.
     
  34. UnRealm2

    UnRealm2

    Joined:
    Jan 21, 2021
    Posts:
    1
    I have a similar problem.
    I'm making game in sigmally.com style.
    When I try to use my controller, the sprite doesn't move. I can't set it as a child to my existing player object, because it doesn't move, I don't know why.
    How can I solve it?
     
  35. crazy_genius

    crazy_genius

    Joined:
    Jan 4, 2020
    Posts:
    17
    is it possible to make the sprite squashed when clicking on the object?
     
  36. crazy_genius

    crazy_genius

    Joined:
    Jan 4, 2020
    Posts:
    17
    nevermind i achieved that very easily
     
  37. Kayumus

    Kayumus

    Joined:
    Jul 21, 2020
    Posts:
    15
    what do you mean "squashed"?
     
  38. lupa984

    lupa984

    Joined:
    Jan 12, 2020
    Posts:
    10
    Hello, I just bought your SpriteSlicer2D and started to use it.
    I used the
    Code (CSharp):
    1. SliceAllSprites
    function which works perfectly.
    Instead, I have a concern about what seems a misfunction of the
    Code (CSharp):
    1. ExplodeSprite
    one. Even in the demo provided in the package the function divides the original sprite in 2 parts. Since in the code there is a
    Code (CSharp):
    1. numCuts=16
    I was expecting to have the sprite sliced into several parts. This is not happening.
    Could you suggest me how to accomplish e multi part explosion?
     
  39. zaferozkel

    zaferozkel

    Joined:
    Mar 10, 2022
    Posts:
    1
    i am having the same problem
    I'm making game in agario.boston style.
    When I try to use my controller, the sprite doesn't move. I can't set it as a child to my existing player object, because it doesn't move, I don't know why.
    How can I solve it?
     
  40. PMK_Games

    PMK_Games

    Joined:
    Jun 4, 2019
    Posts:
    1
    I also confirmed that problem, but I can't fix it.
     
  41. spy37

    spy37

    Joined:
    Apr 16, 2022
    Posts:
    1
  42. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Would this be good for a human body cell simulation?