Monster shadow


Drawing a line in Unity - Happy Glass / Love Balls Style!

Learn how to draw a line in Unity, then attach a collider to it to allow gameobjects to roll, walk and jump on them. Similar to how games like 'Happy Glass' and 'Love Balls' work.

So underrated channel. Thank you for amazing tutorials! Subscribed and ringed the bell for more <3
You are te Best Unity tutorial Master!! 💪💪😎
Gotta catch em all
Música Sgsgsgsg
you deserve many more followers. your videos are great
can i get the source code
Just added it to the description
You Fam
I am so confused as to why this only has 427 views? :O This is one of those Unity tutorials that is just perfect in my opinion!
the grey
move smoothly .. nice tutorial. thanks Matt.
Glad you enjoyed Drawing with Matt :)
srisrid multi purpose channel
Good vidio :)
Chris Mcpherson
@Chris Mcpherson Thanks heaps man. I'll keep delivering the best content I can :)
Chris Mcpherson
@Tarodev to be for real, though, you deserve more views, I'll be subscribing. Thanks for the good tutorial!
You smashed it my guy


all right welcome to drawing with matt i'm going to show you how to
add some lines so that we can interact with these bowls
first let's create our line prefab so new empty game object and let's add a
line renderer to it and add some extra vertices just i'll
show you so we can smooth out the the corners and the the
edges uh let's create a new material
call a line i'll make it a sprite material
and actually no let's keep it white add it to our line renderer that's a
chunky boy so let's pull that down a bit there we go let's make that a prefab
okay now we need to actually draw the line so let's create a
draw manager raw manager script
and let's drag that on there next let's create a script for the actual blind
itself that and then let's open up draw manager
okay so we need a few references here let's grab
first our camera reference and then in start let's get a
reference to it like that next we'll need a reference to our line
prefab that we just made there we go now what we want to do
first is we want to check for input dot get mouse down
and left pointer and if we do what we want to do is we want to spawn
one of these line prefabs so we'll say and we actually need a reference to the
spawned line that we're currently using so let's say
private line current line current line
equals instantiates send in our line prefab now here we need
our mouse position so let's grab that we'll make it a
vector 2 so we'll say mouse pause and we'll say
get our cam um screen to world point and send in our
input.mouseposition so now let's use that as our position
for where we're instantiating and we'll say just our base base
rotation it really does not matter now now that we've got our line
we want to append lines to this line as we drag
so what we're actually going to need is a
public const and we'll make this a float and this will be called resolution
um and let's set it to the 0.1 first resolution so basically what this is
is when we can draw the next point of the line depending on
how much distance it is so if we have this to 0.1 it won't draw a
new point until we pass at least 0.1 of a
unity unit in distance so the smaller you make this
the smoother your line is going to be you can make this up to one and it'll be
like a really janky janky looking line so depending on
what your art style is that will also affect performance let's
now check input get mouse button
so just if we're holding this mouse button we want to
tell our current line to add a new point so let's go to our line script
and we'll need this function here it will say void
set position and we'll take in the new position that we want
so in here we'll need a reference to uh
line renderer like that
and we first we want to say can we lay this point
uh should we should we lay it is it past the resolution threshold
and so on so let's create a new private function here
return a bull and we'll say can append and we'll give it the position that
we're trying to append to so first i want to ensure that if it's
the very first point just always say yes so we'll say
if renderer position count equals zero
well in that case return true otherwise we want to see if this new
point is beyond the threshold of the
resolution so return vector to distance
and we'll get our last position that we've laid down so render our
position count minus one and then the next position will be our
new position and if that is in fact more than our
draw manager resolution then we will return true
so we'll say here if can append us and we'll reverse it so if
we cannot append return out of this function because we
do not want to set this new point if we do we'll go renderer position
count and we'll add an extra point to the
array and then set position and in here we'll
get our last point so renderer position count minus one
and we'll set it to this new position so now back in our draw manager
now that we've laid down our line we now want to append to it so
while it's down we'll grab our current line
set position and we'll feed it the mouse position
now that should actually be all we need to do this
so go across to unity and let's add the line script
to uh i'll just move my face over there so now that we've got our
line script here add our line renderer to it and just one
thing to note in this positions array make sure it's
set to zero on the prefab because it will do some funny things if
you've got a few points in here um so now that we've got that line on there
on our draw manager just put in our line prefab
like that let's try there we go and on our line manager
i'll show you we can actually add change this up to one
and as you'll see it will be a bit more janky like that
could be good for what you're trying to do for me
i will just keep it at point one now that's all well and good but
our balls will just fall straight through it because there's no collider
attached to it so let's do that now on our line
create a new child and call it collider and make it oh edge collider 2d
alright and as you'll see here there's also an array of points that we can
assign to it so on our line script
let's get a new reference to that private
edge collider 2d like that and now every time we set a point
we want to append to this to the colitis points array so let's do
collider points equals and we need to set it basically to this
renderer's points so renderer
get positions actually that's going to be annoying as
that's a vector3 position and this is not really the format that we want to do
it in so what we'll do is we'll create a list
of vector twos and we'll call this points equals new
effect two points now every time we set a position
let's say we'll add our point to this list and now we should just be
able to easily do points to array
and that will just immediately set the points
to the exact points and we can actually make this a
read only all right so now that we've done that make sure
you set your collider reference in your script
and if we do that we should actually see okay so it's offset a little bit so the
reason for that is this line
is saying that its pivot point is the very first point there
whereas the collider itself is kind of like equalizing its entire transform and
setting it to the very center so what we want to do is we want to set
the collider we want to remove the collider's transform position
we want to remove the lines transform position from the collada
transform position so what we can do is we can say here
collider transform position minus equals transform position
so we're taking the transform position the actual lines transform position
off the collider's transform position and that
should actually do it yep as you can see it's right there so
we should now be able to draw some lines now as you can see the
balls kind of like s slipping through it so if you go to your
line and onto your collider let's actually
set this offset this y offset to maybe
something like i don't know is 0.5 gonna be absolutely
way too much yeah too much set it to like point three
it's probably a little bit still too much but you get the point
and there you have it you've got a game where you can draw
and have objects interact with it and there you go hope you enjoyed if you
did hit the like button subscribe and i'll see you next time