Vai al lettorePassa al contenuto principale
  • 12 ore fa
Trascrizione
00:00Hi, I'm Martin, the creator of Thancade and I get a lot of questions on how do I
00:07build a game using Thancade. Usually you should probably start with the
00:13construction kits. They're full of blocks that are already scripted by someone
00:18else and you can just drag and drop them to make games. However, a lot of people
00:22want to make new kinds of games that don't have kits yet. And this video is
00:28going to be for you. So I have a completely empty game here and we're going to make a
00:36simple physics game where you push around the physics object using by tapping it
00:42and you're supposed to navigate through a little obstacle course without colliding
00:49with anything. And I'll start by opening the inventory going to the gadgets folder
00:56because there are some blocks here with the default physics like this box. So it's
01:05really just a regular block except if I place it in the air like that and press
01:10play it'll fall down because it has physics by default. So I place a few of these and
01:18and this can serve as our object that we're going to push around and then I place
01:24some grass blocks for example. Doesn't really matter but just something to get
01:31started on our obstacle course. Actually let's make a small obstacle here. Like so
01:39now you have to go over that. Right so if I press play now this falls down but it
01:50falls down onto the floor and it's already on the floor. I want for simplicity of
01:55making this course I want it to fall that direction. So I'll go into the inventory and
02:01and open the physics folder and find the gravity block. Set gravity, there it is. Now
02:14this one allows us to change so that this orange object will fall down and it
02:20takes one input which is a vector, a green wire. So I'll go into the values and pick
02:29the vector and just wire that to the set gravity block. And then I can tap here to
02:38change the values. So let's say 10. Just try and yeah and now it falls but upwards. Well it
02:50falls in the direction of this arrow. That arrow tells you which direction the z-axis goes. So
02:58I'll just flip the sign of that to make it fall the other way. All right. Next I want to
03:08push it around a bit. So I'll go back to the physics folder and I'll use the add
03:15force block. This block applies a physical force to an object. So for the object I'll
03:23connect it to to our orange square here. And for the force I'll connect another vector. And let's just set
03:3510 here.
03:38Now you can see it's sliding towards the right because I'm pushing it towards the right. Now let's try
03:45pushing it upwards. I want tapping it to move it upwards. And that's the z-axis. So maybe 100 on
03:57z. Like that.
04:01And of course now it it pushes it upwards all the time. But I want that to happen when you
04:08tap it.
04:09So I'll open the inventory and go to the control folder and use the touch sensor. This one detects
04:18whenever you touch the screen. When you do it will execute anything wired to this. So I'll connect that
04:25to our add force block. And now it's the orange thing falls down until I tap. Then I apply the
04:38force.
04:40Actually let's make it only happen when you start tapping. So there's a setting you can change down
04:46here. Right now or by default it's whenever you tap or whenever you touch. But I want it to be
04:54when you
04:55start tapping. So it's when it begins sensing a touch. And I probably need to compensate for
05:06by making the force a bit bigger. Because now we're only applying it once. Like that. Maybe even bigger.
05:20Yeah. Next. Right now I can tap wherever. But I want you to tap the the object you're pushing.
05:36So I want to detect whether we're tapping that or whether we're tapping something else.
05:44So to do that I can use the touch sensor's coordinate outputs. So it tells us where we tapped.
05:53So if I go into the math folder I can translate that into world coordinates.
06:00So instead of knowing where on the screen I tapped I can know
06:04where in in this world we're building I tapped. So I'll plug that in.
06:11And actually let's inspect what we get there.
06:15Any of these wires we can connect in the values folder and inspect block just to look at what the
06:24values
06:25are. So now you can see a lot of coordinates here.
06:29And when I tap it tells me where I tapped. But I want to know whether this orange square is
06:40in is where I tapped.
06:44So I'll go into the let's see objects folder.
06:49There is an object called raycast or a block called raycast.
06:54Basically it's kind of a laser sensor.
06:57It shoots a line from a position to another position and then it reports whatever it hit.
07:04Both the object and the position. So if I connect that there
07:10then I get the object. Let's inspect that too.
07:17I'll use the inspect object
07:21block. So now if I tap the floor it just says none. If I tap the block it says
07:36zero. And these numbers they're just identifiers. It doesn't really matter what number it is,
07:42but it allows us to recognize what we tapped. So I want to compare that number with the number
07:48coming from this pink wire. So let's feed that into a variable to store that value. So I'll open
07:57the variable folder and use pink variables because it's a pink wire. I'll connect that there.
08:06And just to make sure we can inspect that too.
08:11So you see now the variable has the value 2. When I tap our orange thing it's also 2. So
08:24we can just
08:24compare those values. So I'll go into the math folder and find the equal objects block. So I'll just rewire
08:36those
08:37there. Let's trash these.
08:45Now that will check whether it's the same object that I tapped.
08:49And it will feed out true if they're the same. And I want to add the force if they're true.
08:56So I'll go
08:56into the control folder and pick the if block. Just connect that there. So instead of adding the force
09:04whenever I tap I want to do the check. And if that's true then I want to add the force.
09:11So let's try that.
09:13So now when I tap on the floor nothing happens. But when I tap on the orange square then it
09:21adds force.
09:24So now we actually already have some control over it. We can move it up and down.
09:32But I want to push it left and right too. So I'm thinking like when you tap it closer to
09:43the left edge it
09:43should push it away towards the right. And when you tap somewhere here it should push it away towards the
09:54So how do we do that? Well this raycast actually gives us the position where we tapped. So if we
10:03had
10:03the position of the object we could compare them. Fortunately there is a block for that. So I'll open
10:10the inventory. Look in the objects folder maybe. Yes. Get position. And I want to check the position of our
10:20object.
10:22Actually I don't even need this wire anymore because I have this variable.
10:27That can help us make the scripting a little neater like that.
10:37So this will feed out the position of the orange square. And this will feed out the position we tapped.
10:49And I want to know how far along the x-axis we tapped. Like if it was on the left
10:56or the right.
10:58So I need to split those vectors so I can get at the x component of the vector. And if
11:04we look in the
11:05math folder there's a break vector block. So I'll wire that there. And I guess I'll use another one
11:14for this. So I'll get both the x coordinates.
11:23And then I want to get the difference between them to use as a force. So I'll just subtract them
11:29from each other. Just a regular minus. And let's inspect what we get from that.
11:39Use the number inspect block.
11:45So now when I tap on the left side you can see the number over here
11:50is negative. And when I tap on the right side it's positive.
11:54So we'll use that as the, we'll add that to the force to push it in that direction.
12:03So let's see.
12:07This is a number but we need a vector as the force.
12:12So I'll open the math folder again.
12:15And there's a make vector block.
12:19So it's the reverse of break vector. So it takes three components and creates a vector
12:25that we can feed into our add force. So I'll use that for x.
12:30and then previously I had this upward force.
12:36I can actually plug that directly in here
12:40as a regular number from the values folder.
12:45What did I have? 2000?
12:49Like that maybe.
12:57Doesn't seem to move right and left but well this is 2000.
13:02And this I don't remember but when we inspected it was like much smaller.
13:07So let's just scale this up a bit.
13:11We'll go back to the math folder and find the multiplication.
13:19Let's make some more room here.
13:26Maybe we can use 2000 there too.
13:29And I'll feed that to the x value of the vector.
13:35And that will be our force that we add.
13:41Well yeah.
13:44Why is it going off in that direction?
13:50I think it's backwards.
13:52Like if I tap left it moves left but I want to push it right.
13:56And vice versa.
13:59So let's just flip the value.
14:02Maybe make it a bit smaller too.
14:04I'll just take minus 1000.
14:09Right like that.
14:12That's what I wanted.
14:16See now we can control this.
14:21Let's build some more level.
14:26See if we can fly through it.
14:38Let's make a little room first.
14:47Like that.
14:49Maybe place this bit higher so you can fall a bit before you start moving.
14:55And we need something we need to navigate through here.
15:02Something challenging but not too challenging.
15:14Let's make a floor down here.
15:19Well that's a high ceiling.
15:21I'll remove some blocks here.
15:25Something like that maybe.
15:28So you're supposed to navigate above this wall down this corridor and then left and then out.
15:36Let's try that actually.
15:44Yeah that could work.
15:48All right let's
15:53let's make it a bit more challenging.
15:55Like right now it doesn't matter what I collide with.
15:59I can just keep playing.
16:02I want to check whether we collided with one of the walls and then we should just lose.
16:09That'll make it more challenging.
16:11So I'll go into the inventory and look in the
16:15control folder I think.
16:18Yeah there's a collision block here.
16:21So this one will trigger whenever this object collides with something.
16:28So I want to check whether this our object collides.
16:34And then when that happens I can wire something to this yellow wire.
16:40Let's look in the we want to lose.
16:43Lose the game game.
16:46There's a loose block.
16:50So I'll wire that there.
16:52Let's try that.
16:56See?
16:59Whenever we collide with the wall we lose.
17:06Much more like a game already.
17:11And actually let's add a sound effect.
17:14That usually adds to the game feel.
17:17So I'll go to the sound folder.
17:21There's a play sound block.
17:24And probably play that when you tap the object.
17:32So after adding the force I will play a sound effect too.
17:38And if I tap down here I can pick from a number of sound effects.
17:44Let's see.
17:52This one will work.
17:57Yeah.
18:00Much better.
18:02Actually let's style the level.
18:06Let's change the background color.
18:08That's the simplest way.
18:14I mean some of these are not very pretty but
18:19that one matches our grass blocks.
18:30Yeah.
18:31All right.
18:31Well.
18:33We can lose.
18:34But we cannot win.
18:36Because we haven't added that yet.
18:38Let's do that next.
18:41So there.
18:44Well.
18:44You should win when you exit this maze.
18:47And there are many ways we could do that.
18:49But I think the simplest would be probably to just compare
18:54where the block is.
18:56And compare that to
19:01the end of the level.
19:04So these arrows are always at the zero position.
19:08So if...
19:09And this is the Z arrow.
19:11So if it's below zero it must have fallen out the level.
19:16And we already checked.
19:17We already got the block's position from here.
19:20So let's just copy that.
19:25There we have the Z position of our orange square.
19:30And let's see if that's less than zero.
19:32Then we win.
19:34So I'll go into the math folder.
19:37And find the less than block.
19:41So I'll wire that there.
19:42And this wire.
19:44By default it's zero.
19:46So I don't even need to connect to zero there.
19:50And I'll copy that if block.
19:52So if that happens I want to win.
19:56So I'll go back to the game folder.
19:58And there's a block for winning.
20:01So I'll wire that there.
20:07Now let's try that.
20:15I lost.
20:16But let's move this closer to the winning.
20:21Still hard.
20:27Yeah that works for now.
20:30Let's move it back.
20:35Well it's starting to look like a game.
20:38Next might be making more levels.
20:41But right now I just threw all the script blocks on the floor here.
20:45And if we make more levels.
20:47We would have to copy all the script blocks.
20:49Which isn't very convenient.
20:51So what you usually do is just place all of this inside one of the game blocks.
20:58That way whenever you use that block.
21:01It will have the script blocks inside of it.
21:03So you don't need to copy them.
21:07So let's just pick one of the blocks here.
21:11Like one of the corner blocks.
21:12And make a custom block.
21:14So we can stuff the script blocks inside.
21:18So down here I have a pencil icon.
21:20And confirm.
21:21That makes it editable.
21:23So now I can actually paint this block for example.
21:27Let's paint it a bit.
21:29I mean you could style this however you wanted.
21:31But I'm just going to leave it orange.
21:35Just painting it so I remember which block it is.
21:38I can actually change the name too.
21:39Let's call it game script maybe.
21:46And now there's a button to open the block.
21:51And that reveals a circuit board here.
21:54That's where you can place block inside of it.
21:57So I'll drag that block there.
21:59And the wire came loose.
22:00So I'll reattach that.
22:03And when I close the block the script block will hide inside.
22:08So I can just drag all of our script blocks into that.
22:16This circuit board automatically expands so that all the blocks fit.
22:21And now when we close it.
22:23And now when we close it.
22:25Much neater.
22:30Let's try playing this now.
22:45Yeah that's a game.
22:48I mean there we have it.
22:51A new game mechanic that hasn't been done in FanCade before.
22:55Made from scratch.
22:58There are like a million things we could do this.
23:01We could make more levels obviously.
23:03Maybe you would like different types of obstacles.
23:07Maybe obstacles that are moving.
23:09More sound effects and camera screen shakes.
23:14Maybe we could even have something other than just a rectangle here.
23:23Like we just add a physics force so it will work for any shape.
23:30Maybe each of the levels will have a unique object you're pushing around.
23:46So that's the end of the video.
23:48And thank you for watching.
23:50Hope to see you on our discord server.
Commenti

Consigliato