Monster shadow

VIDEO

Floppy, physics-based sprites in Unity

Description:
Create fun floppy sprites for your game in Unity. Add a bit of spice to your scene by transforming your static objects into something a bit more bouncy and reactive. This technique makes use of hinge joints and the line renderer component.
ADD A COMMENT

Andreas
I to will make a small game with this technique, it will feature my firends facebook faces and alot of sausage.
Tarodev
Lol I can only imagine
Trần Vĩ Lập
Marvelous technique
Paolo
Just curious, if you made a ring out of the circle colliders, would it result in a jelly-like sprite?
Tarodev
It would! which is funny if you've never seen it made before because you basically just invented soft-bodies! All a softbody is, is a mesh of colliders and joints (then the slightly more complex part is drawing a mesh around the shape). I plan to actually make a video on 3D softbodies one day.
Jez C
This is great, thanks mate. If I wanted to make meaty stuff in a different shape, is it the same kind of method? Can you add joints between more than two objects?
Jez C
@Tarodev I'll try that. I did move the line around but it didn't seem to affect the sprite I had. High chance I'm doing something wrong lolol
Tarodev
@Jez C Hahaha! Glad my tutorial is helping a good cause. I think you need to raise the width of the line renderer to give them a bit more... girth.
Jez C
@Tarodev ah, I'll have a play around. I'm super new to this. I tried to umm.. Make something lol https://twitter.com/JezCorden/status/1374993274331664385?s=19
Tarodev
I suppose your limitation is the line renderer. It's quite flexible though and you can define custom widths for each segment. You can certainly add joints to join multiple objects. For example you could make a bunch of loose objects with rigid bodies and draw a line over them with a rope texture, then connect each end to the objects. Glad you found it helpful!
srisrid multi purpose channel
This will help me
srisrid multi purpose channel
YES
Tarodev
Go make things floppy :)
DurVids
Great stuff! Keep the tutorials coming, lots of great info.
SEE ALL COMMENTS


Transcript:

all right let's make this meat floppy so i'm going to pull out a circle sprite
i'll add a circle collider to it i'll add a rigid rigidbody2d
and i'll zero it out i'll put it over here
[Music] let's remove the trans uh remove the
opacity a little bit so that we can see and then just duplicate it like this
so that they're overlapping like that now on
the first set not including the very last one
let's add a hinge joint 2d to it and set limits and
whoops and we'll make the angle limits minus 10
and 10. that will that will restrict its movement so
basically if we didn't set limits on this it would just completely flop
around and it doesn't look too good um so now i'm
grabbing my first circle i'm going to drag my second
circle into the connected rigid body and then
moving on to the second circle i'll drag my third one
and so on until we reach all the way to the end and if
you get mixed up and you put him in the wrong place you'll know immediately
as soon as you press play because it looks ridiculous
and the last one and if we just remove the mate there
this should actually just flop as it is like that so if we move it across you'll
see it a bit more like that that's not too fun yet though
so now what we're gonna do is we will write a script and we'll
to to help us render the the mate texture on top so
create a new script let's call it floppy renderer or whatever you want to call it
open it up we're going to need a reference to a
line renderer because that's what we're going to use to render this line
and we'll need a reference to uh uh transform points that we're going to
set it to um in our start let's say renderer
position count equals and we'll set it to how many points there are
and then every frame we're going to set renderer set positions equals to our
points and we'll grab the positions out of
those points like that and then we've got to convert
it to an array because that's what set positions take x
and that should be all we need now let's click on our first circle and
we'll add a line renderer and we'll add
our script here put our line renderer into
the um into the script and then also grab all of our points and put them in
the points there now this won't actually work while we're
not in play mode but just to show you how it does work i'm going to turn off
all of our sprites and the as you can see doesn't look too
pretty yet um a way we can make it actually render
while we're in play mode is we can do this
on draw gizmos now we're going to need this two times
so let's create a new function for that let's just say
private void draw line and we'll take that and put that there
now we can run that there and also in updates
like that and because we're actually running this
position count in start this on draw gizmos is not grabbing it so just while
we're in the editor let's just set that that won't run uh actually in play mode
or when you when you uh compile your game
so it doesn't matter about the performance too much
yeah it's a little bit jagged on the end there so you can actually come down to
your line renderer and you can add some end cap vertices
and it makes it a little bit more more like it like a patty all right so
to get our little meat texture on there now
what i'll do is i'll create a material call it mate
i'll drag my mate onto the albedo or whatever you're using
um i'll make this a default sprite texture now on our line renderer
we'll drag the mate onto there and you'll see a few things one
it's not actually going all the way to the edges here and two we've got this
silly little thing on the end here so to get rid of the little thing on the
end just remove your end cap vertices like that and to make sure it goes all
the way to the end of our collider here on your first one create a child and
just call it left i don't have a any colliders or
rigid bodies on this it's just a little placeholder
on the right here call this one right like that and now on our line renderer
we have to just rearrange these a little bit so let's
restart that if you click this little padlock up here
it makes it so that you can lock this inspector pane so then we can drag
multiple objects and select multiple objects and it doesn't turn this one off
so let's start with our left one let's put that one in first
and then let's grab all of our segments and then finally just put the right one
in so now as you'll see it goes all the way
to the edges and now if we press play
we've got a floppy piece of mate that looks pretty cool um to make a
prefab of this just select the middle one create a
game object let's call this ingredient and then
take it out and then just parent all these segments to the ingredient
and then make a prefab like that now that we've got that we can just
add a few and then watch them fall there we go looks pretty cool so you can
make like a bunch of ingredients i actually made a game using this
technique it's called floppy burger if you want to check it out
and i hope you learned something if you did thumbs up subscribe and
i'll see you next time you