LoneX
LoneX
  • 2
  • 41 352
Unity SoftBody 2D tutorial using sprite shape
Unity 2D soft body tutorial using sprite shapes, this tutorial shows how to create a 2d soft body character like jelly in 2d using unity.
Let me know if you're intrested in getting the character in the intro from the asset store.
Binary Lunar Ref: th-cam.com/video/h_bSGoztB2g/w-d-xo.html
Music : www.bensound.com/
มุมมอง: 40 900

วีดีโอ

ความคิดเห็น

  • @chewwy-0
    @chewwy-0 หลายเดือนก่อน

    im going to use this on a game i will sent link on this video once the game is done

    • @LoneXeaglE
      @LoneXeaglE 10 วันที่ผ่านมา

      Cant wait !

  • @jugalmakwana4210
    @jugalmakwana4210 หลายเดือนก่อน

    can you plzz share this project because i was not getting how you have made sprite shape profile

  • @Braldis_Creator96
    @Braldis_Creator96 2 หลายเดือนก่อน

    hey dont you want to type the whole code? well i did it (in the other way instead of typing) i used text detect from picture and chatGPT tries to fix it and then it worked! (but its broken) heres the code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.U2D; public class SoftBody : MonoBehaviour { #region Fields [SerializeField] public SpriteShapeController spriteShape; // Fixed declaration [SerializeField] public Transform[] points; // Array of points #endregion #region MonoBehaviour Callbacks private void Awake() { UpdateVertices(); // Call the corrected method } private void Update() { UpdateVertices(); // Continuously update vertices in Update } #endregion #region privateMethods private void UpdateVertices() // Fixed method name and structure { for (int i = 0; i < points.Length; i++) // Fixed loop structure { Vector2 _vertex = points[i].localPosition; // Use the correct index 'i' for points Vector2 _towardsCenter = (Vector2.zero - _vertex).normalized; // Calculate direction towards the center float _colliderRadius = points[i].gameObject.GetComponent<CircleCollider2D>().radius; // Get collider radius try { // Update the sprite shape spline position spriteShape.spline.SetPosition(i, _vertex - _towardsCenter * _colliderRadius); // Tangent calculation for smoothness Vector2 _rightTangent = spriteShape.spline.GetRightTangent(i); Vector2 _newRightTangent = Vector2.Perpendicular(_towardsCenter) * _rightTangent.magnitude; Vector2 _newLeftTangent = -_newRightTangent; spriteShape.spline.SetRightTangent(i, _newRightTangent); // Set right tangent spriteShape.spline.SetLeftTangent(i, _newLeftTangent); // Set left tangent } catch { Debug.LogError("Spline points are too close to each other, recalculate or adjust positions."); // Error handling } } } #endregion }

    • @Alpha-Entwickler
      @Alpha-Entwickler 2 หลายเดือนก่อน

      Yes, its a Hexagon, instead of a circle. Can you tell me if you have the solution?

  • @Braldis_Creator96
    @Braldis_Creator96 2 หลายเดือนก่อน

    GIVE ME THE SCRIPT

  • @XbxStudios
    @XbxStudios 4 หลายเดือนก่อน

    I cannot see the code. Too blurry. But great job explaining!

  • @random_precision_software
    @random_precision_software 5 หลายเดือนก่อน

    Which has better performance?

  • @unitygamedevv
    @unitygamedevv 6 หลายเดือนก่อน

    can i contact you personally?

  • @unitygamedevv
    @unitygamedevv 6 หลายเดือนก่อน

    Very nice tutorial but i don't find about sprite shape profile tutorial on everywhere!

  • @санитарпсихбольницы
    @санитарпсихбольницы 9 หลายเดือนก่อน

    Nice ❤❤

  • @UsamaIrshad-s8g
    @UsamaIrshad-s8g 9 หลายเดือนก่อน

    can't understand the way how you're assigning the rigidbodies in connected bodies because of too much speed and no guidance about it.

  • @tommytress77
    @tommytress77 9 หลายเดือนก่อน

    Please upload more

  • @watercat1248
    @watercat1248 ปีที่แล้ว

    I'm not how easy can the be, but if physics like that made in 3D game you can esly able to make slime and jelly. Now that I think about you able to make slime and jelly in 2D game's as well.

  • @garrukthewildspeaker262
    @garrukthewildspeaker262 ปีที่แล้ว

    Amazing! But how did you make the central fill texture to deform?

    • @LoneXeaglE
      @LoneXeaglE 11 หลายเดือนก่อน

      The fill follows the sprite shape. for the internal organs, I had to add another texture that follows the transform of the center point, and the its scale is influenced by the minimum distance between each two points.

  • @Pepinho_xD
    @Pepinho_xD ปีที่แล้ว

    you are a god in my life thanks

  • @Pixelkvist
    @Pixelkvist ปีที่แล้ว

    Unfortunately, I can't seem to delete nodes when I have selected them. If I select a node, it turns yellow but if I press Delete, it just deletes the whole game object. :/ So frustrating!!! So I can't make a triangle, which is what I was planning, and if I accidentally add an extra node, I have to delete the whole game object and start over... Also, I'm on Windows and not a Mac and it even says in the documentation for 2dSpriteShape to use Del/Delete to delete a selected control point! I've tried Ctrl+Del, Alt+Del, Shift+Del... Nothing works!

    • @LoneXeaglE
      @LoneXeaglE ปีที่แล้ว

      The number of nodes can be set throught the gameObject's attributes in the right panel 😉

  • @AnhNguyenViet-jw9ut
    @AnhNguyenViet-jw9ut ปีที่แล้ว

    Thanks man, you have just saved my career :(

    • @LoneXeaglE
      @LoneXeaglE ปีที่แล้ว

      Very glad i could help man !

  • @petar8459
    @petar8459 ปีที่แล้ว

    everything works exept the sprite shape is too large and isnt even at the border of the points pls help

  • @michaelgreenhut180
    @michaelgreenhut180 2 ปีที่แล้ว

    It's a good start. It's not there yet in terms of explanation. Nobody expects an 8 minute video to to be super comprehensive, but you would do well to explain a bit more; mainly -- how did you make the sprite shape graphic? You have a tiny shot of it along the side with no focus or explanation on how to get it to look the way it does -- for example, I made a circle with a border in Gimp, thinking I just had to drag it on and your code would make it look all fluid, but not so. You also did a magic trick from 3:48-3:52 that you completely failed to explain. Do you need to make a square? Should it tile? What kind of Sprite Shape are you making -- open or closed? Answer those basic questions and you'll have something substantial. I would like to see how you set up that TopVirus1 profile, at the very least.

  • @thethirdkate
    @thethirdkate 2 ปีที่แล้ว

    It's really hard to follow the setup of the joints, everything goes fast with no explanation of what you're doing.

    • @LoneXeaglE
      @LoneXeaglE 2 ปีที่แล้ว

      I appologize about that. I'll consider it next time. Thank you for your feedback 😉

  • @cocoduck7745
    @cocoduck7745 2 ปีที่แล้ว

    Great video man, can you also make a tutorial on how to automatically smoothn out exposed edges of a texture. Kinda like terraria where after you mine dirt block the exposed edge of sprite automaticly smoothen itself.

  • @denosorus
    @denosorus 2 ปีที่แล้ว

    Bad Explanation,the fonts are too small and u speeded the connecting joints part

  • @zeusdelolimpo2882
    @zeusdelolimpo2882 2 ปีที่แล้ว

    que gran informacion, para los autodidactas me suscribo, saludos desde Peru

    • @LoneXeaglE
      @LoneXeaglE 2 ปีที่แล้ว

      Gracias ! 😄

  • @BBdaCosta
    @BBdaCosta 3 ปีที่แล้ว

    Great video, lot's of information and very easy to understant

  • @aoufiayman6274
    @aoufiayman6274 3 ปีที่แล้ว

    well done video mate, I don't understand why the need to put the center object inside the points list? you could have just ended the loop at the condition : i<points.length and set the size at 6.

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Thanks a lot mate! And you need it in to control the maximum distance betwenn the center and the rest of the points. I could've put it in a variable on its own but its cleaner it belongs with its familly :D

  • @duyngo8608
    @duyngo8608 3 ปีที่แล้ว

    Hello can u share the project. I try to make soft body many way but it's always lost the form

    • @vikramsingh-io6hu
      @vikramsingh-io6hu 2 ปีที่แล้ว

      same thing happens to me. did you find the solution?

    • @duyngo8608
      @duyngo8608 2 ปีที่แล้ว

      @@vikramsingh-io6hu No i dont. If u find out, pls let me know.

    • @petar8459
      @petar8459 ปีที่แล้ว

      I think you should lower the mass and the gravity if it just plumets down with no support

  • @Gianluca_Bompadre
    @Gianluca_Bompadre 3 ปีที่แล้ว

    Thanx man

  • @lightnguyen4933
    @lightnguyen4933 3 ปีที่แล้ว

    Hi, thank you for creating this, but What would it look like if it had an L shape?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      I suppose you would need to find the right rigidbody pairs to couple with your spring and hinge joints. It takes some trial and error but i believe it can be done.

  • @kreuzaug1143
    @kreuzaug1143 3 ปีที่แล้ว

    It doesn't work for me sadly. I checked every line of code and I did everything exactly the way you did but at the end the sprite shape is always messed up. It's way too far up and when the body is smashing against the wall the whole sprite shape is rotating around the body. Any Idea what I did wrong?

    • @cocoduck7745
      @cocoduck7745 2 ปีที่แล้ว

      Use bones instead in sprite editor. Same principle of using colliders and works great.

    • @michaelgreenhut180
      @michaelgreenhut180 2 ปีที่แล้ว

      Similar problem -- the sprite shape doesn't conform at all to the points, no matter how exactly I follow the code; all it does is stop against the bottom collider and rotate back and forth while the points do the jelly thing independently of the sprite shape.

    • @michaelgreenhut180
      @michaelgreenhut180 2 ปีที่แล้ว

      This helped me -- 1) remove "auto configure distance" from all the joints 2) set all the gravity on the rigidbodies to 0.25 in the video -- he doesn't highlight this but it's how he has it. 3) remove the center node from the transform array. There's no reason for it to be there.

  • @six2gaming894
    @six2gaming894 3 ปีที่แล้ว

    will this be laggy on a larger number of soft bodys like maybe 128 to 256?

  • @riles2645
    @riles2645 3 ปีที่แล้ว

    Last question... When I bash the ball semi hard it breaks the only thing that seemed to fix this is making the frequency higher on the spring joints that are connected to the center point do you know how to fix this?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      You could make the center circle collider slightly bigger than the others but really the best way to do it is through scripting some kind of behaviour for when it breaks.

  • @riles2645
    @riles2645 3 ปีที่แล้ว

    how did you add the eyes?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Added then as a sprite and out them as child to the center point.

  • @riles2645
    @riles2645 3 ปีที่แล้ว

    does anyone know how to add friction to these softbodys?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Yes just add a physics material and set the drag value to something above zero.

    • @riles2645
      @riles2645 3 ปีที่แล้ว

      @@LoneXeaglE I'll try again

  • @elsedev7112
    @elsedev7112 3 ปีที่แล้ว

    I use godot and i watch shader unity wow lol

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      well it's good to have perspective :D

  • @niksu95
    @niksu95 3 ปีที่แล้ว

    U got 5th on my home page congrats

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Thats encouraging thank you

    • @niksu95
      @niksu95 3 ปีที่แล้ว

      I am always happy when someone hearts my comment this is the third time thank you 🙂

  • @عمرالعراقي-ل4ش
    @عمرالعراقي-ل4ش 3 ปีที่แล้ว

    Thx man I hope you can in the future publish video about how to make stickman and make him walk

  • @korays0726
    @korays0726 3 ปีที่แล้ว

    wow

  • @Notreal76
    @Notreal76 3 ปีที่แล้ว

    Good Tutorial. I am sure your sub count will rise quickly if you keep doing Tutorials in this quality.

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Very encouraging thank you for your feedback

  • @billjeason6635
    @billjeason6635 3 ปีที่แล้ว

    Awesome Project Guys!!

  • @lazylizarts
    @lazylizarts 3 ปีที่แล้ว

    Thanks mate!!! Great video

  • @bluedev6304
    @bluedev6304 3 ปีที่แล้ว

    ( 6:50 ) After I followed the steps to fix it didn't get fixed for me.

  • @Marvin_Hermann
    @Marvin_Hermann 3 ปีที่แล้ว

    Hey, is it possible to use a sprite rather than a sprite shape profile?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      I suppose you could use Inverse Kinematics and bind them with a sprite so that it deforms in a certain way, but I don't think that's a good approach. alternatively , you could use a mesh renderer, give it a texture, and deform it via script. here's a good tutorial to get started with meshes th-cam.com/video/gmuHI_wsOgI/w-d-xo.html

    • @Marvin_Hermann
      @Marvin_Hermann 3 ปีที่แล้ว

      @@LoneXeaglE Okay, thank you very much ^^

  • @SaNaLk
    @SaNaLk 3 ปีที่แล้ว

    // For Lazy GameDevs using UnityEngine; using UnityEngine.U2D; public class SoftBody : MonoBehaviour { #region Constants private const float SpineOffset = -0.5f; #endregion #region Fields [SerializeField] public SpriteShapeController SpriteShape; [SerializeField] public Transform[] points; #endregion #region MonoBehaviour Callbacks private void Awake() { UpdateVerticles(); } private void Update() { UpdateVerticles(); } #endregion #region PrivateMethods private void UpdateVerticles() { for (int i = 0; i < points.Length - 1; i++) { Vector2 _vertex = points[i].localPosition; Vector2 _towardCenter = (Vector2.zero - _vertex).normalized; float _ColliderRadios = points[i].gameObject.GetComponent<CircleCollider2D>().radius; try { SpriteShape.spline.SetPosition(i, (_vertex - _towardCenter * _ColliderRadios)); } catch { Debug.Log("spine points are two close"); SpriteShape.spline.SetPosition(i, (_vertex - _towardCenter * (_ColliderRadios + SpineOffset ))); } Vector2 _1t = SpriteShape.spline.GetLeftTangent(i); Vector2 _newRt = Vector2.Perpendicular(_towardCenter) * _1t.magnitude; Vector2 _newLt = Vector2.zero - (_newRt); SpriteShape.spline.SetRightTangent(i, _newRt); SpriteShape.spline.SetLeftTangent(i, _newLt); } } #endregion }

  • @burakgidelim
    @burakgidelim 3 ปีที่แล้ว

    Thank you for this tutorial. I have a complaint about expression. Please, dont be fast guy.

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Point taken, thank you for the feedback sir!

  • @BinaryLunar
    @BinaryLunar 3 ปีที่แล้ว

    Thanks for mentioning our channel.

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      It was very helpful and a smart way to solve the problem, the pleasure is mine!

    • @BinaryLunar
      @BinaryLunar 3 ปีที่แล้ว

      @@LoneXeaglE Can we redo your video and mention your channel ?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      @@BinaryLunar sure, no problem! Education should be free :D

  • @shauryasingh3511
    @shauryasingh3511 3 ปีที่แล้ว

    bro can you not just give a github link like seriosly i am getting mad

    • @petar8459
      @petar8459 ปีที่แล้ว

      i just want the blobs to blupp

  • @miscae4990
    @miscae4990 3 ปีที่แล้ว

    Hi, thank you for creating this, but for some reason the last part that is supposed to fix the twists did not work for me. If your soft body looks like this and stays like this even after you put in the code in the video, I have a potential solution. I am new to Unity so I did not understand the science behind the code, sorry if it's just a beginner thing. imgur.com/a/xpmPAsu (I take a screen shot) Code in the video: Vector2 _newRt = Vector2.Perpendicular(_towardsCenter) * _lt.magnitude; Vector2 _newLt = Vector2.zero - (_newRt); Changed: Vector2 _newLt = Vector2.Perpendicular(_towardsCenter) * _lt.magnitude; Vector2 _newRt = Vector2.zero - (_newLt); Basically I think what happened was is that the right tangent (_newRt) took the magnitude of what was suppsoed to be the left tangent, so when you subtracted the vector2.zero of the left tangent, you got what was supposed to be the right tangent (I think?) I just switched some of the variables around and it worked! Thank you very much for the video by the way :D I am just a bit confused though, how come your code worked for yours but it did not work for me? Did I somehow flip everything around or something?

    • @LoneXeaglE
      @LoneXeaglE 3 ปีที่แล้ว

      Thank you for your comment buddy. I dont think the problem was multiplying by the wrong magnitude since doing so would just make those tengeants a bit shorter or longer, it wouldn't change the direction of the vector since its always positive (its the square root of x²+y²). maybe you assigned spline.getRightTangeant() to _lt instead of getLefttangeant(); or your scale on the y or x axis in the sprite shape is negative. eitherways im glad you figured it out by yourself ! And thanks for the feedback.

    • @Advencher
      @Advencher 3 ปีที่แล้ว

      thank you, guy