Welcome back.
As we finished in the last lecture, you can see that currently, Barry, when we click on play just
kind of stops there.
He's not like the ball that was able to roll down this hill using physics.
He's just kind of stuck there and that's fine.
We could solve this by going down the path of adding physics, like adding force that pushes the player
along, that pushes the player a different amount up hills and downhills.
We can play around with gravity.
There's play around the friction on the snowboard.
There's a lot we can do there, or I can show you a really cool feature in Unity and we'll use that
cool feature to make our snowboarder move.
And that cool feature is using an effector and the sort of effector we're going to use is the surface
effect, the 2D.
If you jump over to the Unity documentation, I've given you a link against this lecture for that.
In the resources section you can see that the surface effector to DH applies tangent forces along the
surface of colliders.
What does that mean?
Well, this is analogous to a conveyer belt, so we're trying to make a conveyor belt by adding some
sort of force that we apply along our collider.
So we've got our collider that's going along the edge of our of our world here.
We want to apply a conveyor belt effect to something that pushes anything, that collides with it in
a particular direction.
So it's going to conveyor belt it along.
There's other types of effectors.
Let me just jump back to effect as to do that.
You can play around with their surface effector point effector platform effector buoyancy and area effector.
So there's a few of these that you can play around with.
But for now we're just focusing on this conveyor belt or service effector to DX and it's going to be
easy peasy to implement this.
So what we need to do is click on our level, sprite shape, jump down, find our add component search
for effector.
We're looking for the surface effect, the 2D click, there we go, scroll down.
We can have a look at the details on that and let's click on play and see if anything happens at this
point.
Okay, nothing's happening.
Of course, that means we need to do a little bit of sleuthing in here.
And if you have a look at our Edge collider, you can see there's a setting in here which says Used
by effectors.
In other words, it's saying if you drop an effector on here, it's not necessarily going to know which
edge collider you want to be using because you might have a few edge colliders, but if we say used
by effector now the effector will know, aha, this is the edge.
Collider When something touches this, I'm wanting to push along that edge.
Collider So now when we click on play, we'll see what happens.
Okay.
He's moving.
Wasn't moving before.
Moving very, very slowly.
So let's have a look at our settings in here.
We've got our four speed, we've got our speed variation, we've got our force scale.
Let's try adding 20 into speed and see what happens in here.
So when we click on play now with 20 and our speed for service effector, you see problem Barry's getting
pushed along.
However, he's getting stuck at this point here and that's something that we had our initial success.
Let me just move him up the hill a little bit here.
Make sure you clicked on the parent whenever you do any of these things, because if you click on just
the top, then woop you just move the top, but not the entire game object.
Not Barry in his entirety.
So popping up here, I'm going to click back on my level shape and I'm going to move this down the speed.
I'm going to change that back down to ten just so he's not moving quite so rapidly and flying off the
thingy.
So you can see here he's touching got speed, speed, speed, speed, speed.
You can see the camera is flowing over here, doesn't really rotate very well goes up there up does
a little bit of a jump all good making progress bump and then it gets stuck and falls through the world.
Now the effect is working, but we've got an issue with our collision that's easily solved.
If we click on Barry, we find Barry's rigid body.
You can see collision detection is discrete.
We want that collision detection to be continuous.
So that's going to require more processing power because Barry's the star of the show, we don't mind.
It's going to do a more continuous collision detection.
So if I'm right with this, he will fly down the hill, do his kind of weirdness, but he's not going
to get stuck because we're doing a much better collision detection.
And on this hill, our effector or our conveyor belt is still going to keep pushing him along as we're
expecting it to do.
So that's mission accomplished.
The effector is that easy to move things along if we want to twiddle with it a little bit, you can
see while we're clicked on our level, sprite shapes don't play mode.
If we get there and change the speed to say, I don't know, minus ten, then it's going to make Barry
go backwards because it's pushing in the other direction.
The conveyor belt is going backwards.
We put it back up this way, but do it to a smaller amount.
Then he's moving along.
If you increase the force scale, that's a way of saying don't respond to any of these gravity things
like up the hill.
It's going to go up the hill exactly the same no matter how steep the hill is.
But if I push this all the way down to say 0.001 on the force scale, he's kind of stuck on the hill,
doesn't have enough force to push him up.
And if I increase that, then it does.
If I put it down to zero, not enough.
So a little bit more force, a little bit less.
So you can see there's a relationship.
Speed is how fast he's going to move or how fast the conveyor belt is moving and the force is how much
we're applying that force to counteract any gravity that we might have with our game object.
Where's that gravity coming from?
Well, it's currently on Barry.
If you click on Barry, you can see that he has a gravity scale of one, which is fine.
We can play around with that at some point, but it's cool for now.
So little sprite shape, I'm going to put this back to actually if we get out of play mode because I
was in play mode while I was doing that, it'll reset our values back to what they were when we first
clicked on play mode.
So there we go.
I love Effectors and I love this surface effector.
It's so powerful.
Just by dropping that in instantly, we've got this character moving along, looking like he's a snowboarder.
And one cool thing, if you haven't noticed it already, if you were to increase speed up and decrease
speed, notice how it only affects him when he's in the air.
So if I go woop really fast and then put it all the way down really low, is he going to land on the
world loop?
And he's going backwards now?
So I put it all the way to backwards, but it's only if you're touching the effector that that has an
impact when you're in the air.
It doesn't.
Also it's good to know is that we can modify this value here in our code.
So if the player pushes a key on the keyboard, we can have them speed up if we wanted to, to give
them a boost.
So that's really cool.
Whenever you see these values on the components, just have a think about the fact that, you know,
we can modify these in our code to do cool things such as with the speed.
So there we go.
There's an introduction to effectors, specifically the service effector.
Now we have our snowboard out moving along our world.
I'll see you in the next lecture.