Search Unity

Jelly Sprites - Soft body sprite physics system

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

  1. io-games

    io-games

    Joined:
    Jun 2, 2016
    Posts:
    104
    Thanks! Updated to 5.5 and the problem gone
     
  2. dergachoff

    dergachoff

    Joined:
    Aug 7, 2015
    Posts:
    4
    Hi, @mrsquare!

    You've made a really great asset! But I've stumbled upon an issue. When I set JellySprite mode to Grid through inspector, I get no gizmos in the scene and the following error in the console:

    NullReferenceException: Object reference not set to an instance of an object
    JellySprite.OnDrawGizmosSelected () (at Assets/Plugins/JellySprites/Scripts/JellySprite.cs:2406)
    UnityEditor.DockArea:OnGUI()

    I'm using Unity 5.5.1.f1
    Any ideas how to fix it?

    Thanks!
     
  3. dergachoff

    dergachoff

    Joined:
    Aug 7, 2015
    Posts:
    4
    Also: any way to add a 2d joint (like a hinge joint) to the central (or any other) body?
     
  4. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry for the slow reply. Hm, that's odd - I'm on a slightly earlier version, but not seeing that. Let me upgrade to 5.5.1.f1 and give it a try.

    Re. adding a joint to the Jelly Sprite - you'd have to do that programatically due to the reference points being created at runtime, but you'd just need a bit of code like this:

    Code (csharp):
    1.  HingeJoint2D joint = GetComponent<JellySprite>().CentralPoint.GameObject.AddComponent<HingeJoint2D>();
    Or alternatively, set up your hinge joint in the inspector and then just attach it to the central Jelly Sprite body at runtime.
     
  5. smasters654

    smasters654

    Joined:
    Dec 20, 2013
    Posts:
    46
    Hi @mrsquare

    I sent you an email about you jelly mesh asset regarding 2 materials on an mesh a bit ago but I haven't heard from you. I would have posted this in the jelly mesh forum post but it seemed pretty dead on there sorry. Please let me know how to fix this issue? Thanks!
     
  6. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hi @mrsquare

    Is it possible for you to clarify how to add distance joints or hinge joints etc. to jelly sprites? It would be great. Thanks.
     
    Last edited: Nov 20, 2017
  7. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry for the slow reply.

    So, from a script attached to the Jelly Sprite, you can access the Jelly Sprite reference points like this:

    Code (csharp):
    1. JellySprite jellySprite = GetComponent<JellySprite>().ReferencePoints[x];
    Reference points are the physics objects that control the Jelly Sprite behaviour - you'll have a different number depending on what configuration you're using. The one at index 0 is always the central reference point, and the others will be attached to that.

    The reference point itself is just a little data structure that contains a gameobject and some other info. So to add a distance joint, you just add a DistanceJoint2D component to the reference point gameobject as you would with any other gameobject:

    Code (csharp):
    1. // Get the Jelly Sprite component
    2. JellySprite jellySprite = GetComponent<JellySprite>();
    3.  
    4. // Get the reference point gameobject (pass in an index from 0 -> jellySprite.ReferencePoints.Count)
    5. GameObject jellySpriteReferencePointObject = jellySprite.ReferencePoints[0].GameObject;
    6.  
    7. // Add a new distance joint
    8. DistanceJoint2D distanceJoint = jellySpriteReferencePointObject.AddComponent<DistanceJoint2D>();
    9.  
    10. // Configure the distance joint
    11. distanceJoint.connectedBody = someOtherRigidBody;
    12. ...
    13.  
     
    kapopixel likes this.
  8. Goodyearpimp

    Goodyearpimp

    Joined:
    Jun 5, 2014
    Posts:
    3
    I've purchased both JellyMesh & JellySprite recently (great work by the way MrSquare).


    I was hopeful that I could use this in tandem with SVG Importer from the Asset Store (Jarolic's). I am unable to use either JellyMesh or JellySprite with the Unity MeshRenders or MeshFilters generated automatically when importing SVGs through his asset. Any help???
     
  9. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry, I'm not familiar with that asset (and sadly is a bit pricey for me to give it a test!). If you could send me an example project containing some meshes you've used it to generate, then I might be able to diagnose the issue.
     
  10. jooyeon0103

    jooyeon0103

    Joined:
    Sep 26, 2017
    Posts:
    1
    Hello,

    I instatiated many Jelly Sprite from PinkBlob in demo scene.
    I make prefabs, and instantiate from code.

    But some PinkBlob instance have been teared. I attached a screen shot and marked red box.
    How can I avoid this sprite error?

    Thank you.
     

    Attached Files:

  11. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry for the slow reply.

    Its hard to tell without seeing it in motion, but judging by the screenshot it looks like some of the bodies are getting stuck on something and/or getting a very large force applied to them, which is causing them to move far away from their default formation. Assuming that you don't have any invisible platforms or anything in your scene that they're getting stuck on, you could try increasing the collider radius, or maybe using the 'Attach Neighbors' options, both of which should help them keep their shape a bit better.

    Having said that, that is a very large number of physics bodies + springs that you have in a confined space, so it could just be the physics engine freaking out! Might be worth reducing the number of Jelly Sprites and/or bodies per Jelly Sprite, if that is an option.
     
  12. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    Will the Jelly Sprites jiggle by only moving them around (dragging) without collision? I want the jiggle effect this system has, but never having to collide with any terrain or objects.
     
  13. HyunMok_Moon

    HyunMok_Moon

    Joined:
    Oct 14, 2016
    Posts:
    24
    Hello mrsquare,

    I want to change tint color in UnityJellySprite component.
    I changed m_Color value in runtime.

    from JellySprite.cs
    // Tint color
    public Color m_Color = Color.white;

    from my code,
    transform.GetComponent<UnityJellySprite>().m_Color = new Color(1f, 1f, 1f, 0.5f);

    I can see "Tint Color" value is applied in Inspector window.
    But sprite image is not change in Game view.
    When I change from Inspector, Tint Color in UnityJellySprite component I can see in Game view.

    I changed Alpha value.

    renderer.sharedMaterial.SetColor("_TintColor", colorValue)
    it work neighter.

    Thank you.


    I resolved.
    Sprites/Default shader, use _Color property as Color: Tint. so I changed _TintColor -> _Color
    it works!!
     
    Last edited: Nov 7, 2017
    mrsquare likes this.
  14. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yeah, you can turn off the collision on the Jelly Sprite colliders, that shouldn't be a problem (or else just put them into a layer that has no collision).
     
  15. kapopixel

    kapopixel

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

    Have you tested mobile performance of Jelly Sprites lately ? I saw your answer about performance on iPhone4 but it is from May 2014.

    I am using one Jelly Sprite character containing 18 custom bodies with default vertex density settings (10) and wondering if it is OK for devices like iphone 6s and above. I think 18 active bodies mean 36 joints but have no idea what this means in terms of mobile performance. Any idea or experience you can share?

    Thanks a lot.
     
  16. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - yeah, I reckon you'll be fine on a 6s. That's not a huge amount of physics bodies (probably about the same as the demo scene included with the package), and even though the 6S is a few years old, it still has a pretty beefy CPU. Device-wise, I've tested on an iPhone 4S, Nexus 7, and a Galaxy S7 - the S7 is probably the closest match for the 6s, and I can't imagine that having any issue running the demo scene at 60fps+.
     
    kapopixel likes this.
  17. gfaraj

    gfaraj

    Joined:
    Jul 11, 2016
    Posts:
    35
    Hi @mrsquare

    I purchased your asset and it's been pretty great so far. Here's a question for you though. I'm trying to use this in a simple platform game. For the platform I'm using the built-in Platform Effector 2D so that the player can jump through platforms.

    The problem here is that since the jelly has several colliders, when jumping up, it's possible for the character to get stuck in the platform -- only the upper colliders of the jelly passed through the effector, but when it falls back down, those colliders will now collide with the platform.

    Do you have any suggestions on how to make this asset work with platform effectors?
     
  18. chanfui

    chanfui

    Joined:
    May 2, 2017
    Posts:
    11
    I use OnJellyCollisionEnter2D and also the Unity's OnTriggerEnter2D / OnCOllisionEnter2D,

    Because inside the Jelly has more than one collider, causing OnTriggerEnter2D / OnCollisionEnter2D, and also OnJellyCollisionEnter2D being called multiple times.

    How can I make it as one collider to trigger the above collision/ trigger functions only once everytime when the sprite enter / exit the collider?

    Also,
    I use public bool IsGrounded(LayerMask groundLayer, int minGroundedBodies) function but it always return true.
    Is that a bug or I've understand it wrongly? So far I have only 8 colliders, but i put minGroundedBodies as 10 it still return me true.
     
  19. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Nice question indeed. I also want to know if there is a solution to this.
     
  20. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hey @mrsquare,

    Is there a way to deform a mesh dependent to jellysprite's behaviors? So I can create a fake drop shadow. In other words, I am basically trying to copy behaviors of a jellysprite.

    (There is a post about how to animate a jellysprite by attaching jellysprite's sprite to another animated sprite. So basically I am trying to create vice versa behavior of this).

    Thank you.
     
  21. satyamparkhi

    satyamparkhi

    Joined:
    Jul 7, 2017
    Posts:
    2
    My sprite is not showing up and i am getting this error


    upload_2017-12-17_8-49-52.png

    upload_2017-12-17_8-50-19.png
     
  22. satyamparkhi

    satyamparkhi

    Joined:
    Jul 7, 2017
    Posts:
    2
    when i am adding sprite to the script its coming white and also some error

    upload_2017-12-17_10-29-32.png
    upload_2017-12-17_10-29-44.png
    upload_2017-12-17_10-29-53.png
    upload_2017-12-17_10-30-39.png
     
  23. FamilyGamesTime

    FamilyGamesTime

    Joined:
    Apr 27, 2017
    Posts:
    21
    Is there any way to make the jelly change shape in reaction to user input? Specifically I'm wanting it to act like a ball of slime - so if someone pushes on the right side of the jelly, then the right side will squeeze out. I can see how to apply a force but that doesn't seem to do what I'm after.
     
  24. smart-machines

    smart-machines

    Joined:
    Sep 25, 2017
    Posts:
    1
    Hello there and congratulations for this addon.
    I'm using the Jelly Stripes in 2D and I'm trying to get the bounds of the stripe drawn.
    I have seen that in the JellySprite.cs there is many times the value of width and height which are used to build or update vertices but they live only in the scope of some function.
    The curious thing is when I try to access it this value with

    JellySprite jellyBulle = Bulle.GetComponent<JellySprite>();
    Debug.Log(jellyBulle.m_SpriteScale);
    UnityJellySprite UJellyBulle = Bulle.GetComponent<UnityJellySprite>();
    Debug.Log(UJellyBulle.m_Sprite.bounds);

    Where Bulle is the JellyStripe GameObject
    I get the correct values and after that an exception about a null pointer reference : Object reference not set to an instance of an object.
    How it can possible ?
    a reference is giving a null pointer but with a correct value of the reference
     
  25. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    @Drinksarlot maybe try with Attach Neighbors on
    By settings this Z rotation is locked for ref points. If you want the slim rotate again you must set off programatically on Start.
    Set 20 num colliders at 0.1 size. And maybe increase vertex density...
     
  26. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hello @mrsquare
    a bug in transform parenting occured when you load a scene with a jellysprite and unload the active scene because ReferencePoints parent is created in active scene. To avoid this you should add in JellySprite::Start() at line 498:

    Code (CSharp):
    1. // fix parenting
    2.             if(transform.parent != null)
    3.                 m_ReferencePointParent.transform.parent = transform.parent;
    4.             else
    5.             {
    6.                 m_ReferencePointParent.transform.parent = transform;
    7.                 m_ReferencePointParent.transform.SetParent(null);
    8.             }
    Same for JellyMesh I think.


    Another suggesion is to add a ForwardMessage in JellyMeshReferencePoint.cs to use Custom SendMessage. (I have already suggest you for JellyMesh)

    Code (CSharp):
    1.  /// <summary>
    2.     /// Ajout perso pour forward un message lors d'une collision
    3.     /// </summary>
    4.     /// <param name="values"></param>
    5.     void ForwardMessage(object values)
    6.     {
    7.         if (ParentJellyMesh && SendCollisionMessages)
    8.         {
    9.             object[] obj = (object[])values;
    10.      
    11.             ParentJellyMesh.SendMessage((string)obj[0], obj[1], SendMessageOptions.DontRequireReceiver);
    12.         }
    13.     }
    This function help me in my hurt character logic.
     
    mrsquare likes this.
  27. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - sorry for the lack of replies everyone, seems that my email notifications stopped working for some of my watched threads.

    The only explanation that I can think of here is that the null pointer reference isn't coming from this exact bit of code, but something running very soon afterwards. If you click on the error in the console, you should see the callstack, which will show you the exact file/line of code that is throwing the exception - eg.

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. JellySprite.AddReferencePoint (Vector3 position, Single radius, Boolean lockRotation) (at Assets/JellySprites/Scripts/JellySprite.cs:921)
    3. JellySprite.CreateRigidBodiesCircle (Bounds spriteBounds) (at Assets/JellySprites/Scripts/JellySprite.cs:600)
    4. JellySprite.Start () (at Assets/JellySprites/Scripts/JellySprite.cs:451)
    Hopefully that will give some more clues.
     
  28. johnylawless

    johnylawless

    Joined:
    Oct 8, 2017
    Posts:
    3
    Hi @mrsquare
    Great asset, i'm really enjoying playing around with it.
    I am having a bit of trouble with the Scale function however. It seems the higher I scale a jellysprite the more erractic and jittery it behaves, it also seems like the spring stiffness & damping does not match how the original jelly behaved. Is the system too complex to scale by large amounts, or am I just missing something?
     
  29. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - how are you scaling the Jelly Sprite - using the provided Scale() function? If you create a new Jelly Sprite at the size you've scaled the other one to, do the two behave differently?
     
  30. johnylawless

    johnylawless

    Joined:
    Oct 8, 2017
    Posts:
    3
    So here is how I'm using the Scale function, to increase the scale by "1 unit" each time, also scaling the spritescale to use as a reference to the current size.
    Code (CSharp):
    1. float scaleRatio = 1f + (1f/jellySprite.m_SpriteScale.x);
    2. jellySprite.m_SpriteScale *= scaleRatio;
    3. jellySprite.Scale(scaleRatio, true);
    I've added some gifs to show the different reactions.

    Here starting at a scale of 10:
    10_Scale_Test.gif

    And here starting at a scale of 2 and scaling up to 10:
    2_Scale_Test.gif

    The opposite also happens when I scale down from 10, the jelly becomes very loose and floppy, which makes me think its something to do with the length of the spring joint?
    I'm fairly new to Unity and programming in general so I'm at a real loss.

    I've also tried playing around with the gravity scale, spring stiffness, damping, mass, etc... but nothing has had much of an effect.

    Any help would be much appreciated!
     
  31. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Thanks for the info! Let me check it out and I'll get back to you :)
     
  32. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hello @chanfui,

    Were you able to find a solution how to call OnJellyCollisionEnter2D only once on collision?
     
  33. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey folks - sorry for the lack of replies from my part, am getting married tomorrow (eek!) so the last week or so has been crazy busy! Will try to reply when I get a chance, thanks for your patience!
     
    novihunter247 likes this.
  34. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Oh voav that is great mrsquare congratulations and thank you for your support in this limited time !
     
  35. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - so I gave this a test, and one thing I did notice was that the Jelly Sprite's Scale() function multiplies the frequency value of the springs by the scale amount, whereas if you pre-scale the object then the frequency value is simply set to be the value defined by the Jelly Sprite's stiffness.

    You could try removing this line of code in JellySprite.cs on line 2095:

    Code (csharp):
    1. springJoints[jointLoop].frequency *= scaleRatio;
    And this should ensure that the stiffness always remains the same regardless of whether you scale the Jelly Sprite up or down.
     
  36. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - I've uploaded a small script that I wrote to enable this behaviour. If you add it to a Jelly Sprite then it should do what you describe and call the OnJellyCollisionBegin/OnJellyCollisionEnd functions only once when the Jelly Sprite collides with something.
     

    Attached Files:

  37. Zhaddul

    Zhaddul

    Joined:
    Nov 23, 2016
    Posts:
    4
    Is there any plan to make support for tileable 2D sprites?
     
  38. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - no immediate plans, but only because I've not used the tiled sprite implementation in Unity so I'm not familiar with it. I can certainly take a look if there's demand for it though.
     
  39. Zhaddul

    Zhaddul

    Joined:
    Nov 23, 2016
    Posts:
    4
    Under the unity Jelly Sprite script, how would I go abouts incorporating tiled sprite implementation onto the script. I am not talking about tilemaps.

    I'm talking about the the "Sliced" and "Tiled" options on the SpriteRenderer component. I have attempted to modify the script in order to incorporate this function. Basically, I want the sprite to act as a "Sliced" or "Tiled" sprite.

    Any thoughts on what to do/ how abouts achieving this?
     
  40. johnylawless

    johnylawless

    Joined:
    Oct 8, 2017
    Posts:
    3
    Hey, sorry have not had much time to check this out lately, congrats on the wedding by the way!

    I have tested modifying that code and it helped a little, but am still having the same issue. I am wondering if it may be something to do with the relationship between scale and gravity in unity. I would like to have a relatively high gravity to make the jumping more snappy, but maybe this is causing issues when scaling?
     
  41. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    Hi I’m wanting to know how to apply a basic script that will let me move my sprite left, right and jump.
    I have followed script tutorials but none of them worked on the jelly sprite although the script works on a normal sprite.
    Please help, I’m also an ultimate beginner.
    Thank you
     
  42. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Hey - the main difference between a Jelly Sprite and a regular sprite (with physics) is that the regular sprite will have a RigidBody2D component attached to the sprite gameobject itself, whereas with the Jelly Sprite has multiple RigidBody2D components that are attached to separate gameobjects from the sprite.

    You don't really need to worry about the implementation details too much, but just be aware that you can't add forces to the sprite's rigidbody in the usual way. However, the Jelly Sprite code provides replacement functions for most of the common physics functions, so anywhere you see some code doing something like

    GetComponent<Rigidbody2D>().AddForce();

    you should be able switch it to:

    GetComponent<JellySprite>().AddForce()

    and get broadly the same result.
     
    novihunter247 likes this.
  43. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Ah, gotcha - sorry, I thought you were talking about tiled sprites as in 2D tilemaps.

    The Jelly Sprites code kinda tiles the sprite anyway when it first starts. The basic process is:

    1) Take the sprite quad and divides it up into a 10x10 grid mesh (or whatever your vertex density is set to in the asset),
    2) Work out how close each physics body is to each mesh vertex to generate a per physics body influence ratio for each vertex.
    3) Distort the mesh vertices based on the movement of the physics bodies scaled by their influence ratios.

    So if your sprite is already tiled, then that is going to cause issues with step 1, but theoretically you could just skip that and go straight to step 2. So essentially you're taking control of the tiling rather than having the Jelly Sprite code do it automatically. There is a function in the code called InitVertices() - I think my approach would be to try to modify that to just grab the vertex positions and texture UVs direct from the mesh.

    I'll give it a shot and see how I get on - it should be do-able though, I'd hope.
     
  44. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    When ever I’m trying to write a script almost every time it will come up with this error. “The type or namespace name ‘JellySprites’ could not be found. Are you missing an assembly reference?
     
  45. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    When ever I’m trying to write a script almost every time it will come up with this error. “The type or namespace name ‘JellySprites’ could not be found. Are you missing an assembly reference?
     
  46. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    I think I found the problem, error CS0117: ‘JellySprite’ does not contain a definition for velocity.
     
  47. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Ah - yep, try using jellySprite.CentralPoint.Body2D.velocity for a decent approximation (that'll just give you the velocity of the central body)
     
  48. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    So I would replace where velocity would be in the script with that?
     
  49. novihunter247

    novihunter247

    Joined:
    Jan 9, 2018
    Posts:
    9
    D1DDE025-3721-46FF-8903-C985AFF79586.jpeg D1DDE025-3721-46FF-8903-C985AFF79586.jpeg Why does this jump script not work?
     
  50. mrsquare

    mrsquare

    Joined:
    Oct 25, 2013
    Posts:
    281
    Because JellySprite doesn't have a variable called Velocity. Try:

    Code (csharp):
    1. GetComponent<JellySprite>().CentralPoint.Body2D.velocity = Vector2.up * jumpVelocity);
    or

    Code (csharp):
    1. GetComponent<JellySprite>().AddForce(Vector2.up * jumpVelocity);
    (I'd recommend the second option - you'll get more natural behaviour by applying forces rather than manipulating the velocity directly)