Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Tutorials
#1

Direction Detection A.I in sackbots

Archive: 12 posts


Hallo Community.

This is my first tutorial, and it's aimed at Beginner to Intermediate Creators. I hope it will be of some use!

Okay, so let's get started; what if you wanted to make a Metal Gear Solid-inspired sneaking mechanic in your level? How would you go about making the Sackbot A.I? It would have to "know" whether or not you are behind or in front of it, and respond with an appropriate action (unaware if you are behind, aggressive if in front, obviously!)

So how do we determine whether or not the Sackbot "sees" you?

Firstly, we need to define the terms "behind" and "in front" to the sackbot through the logic provided. Let's grab a sackbot.

http://i3.lbp.me/img/ft/8133193825818e497be85675d4924b66140903be.jpg

Good. I've placed him in a very basic environment, but you can do whatever you like. Now let's open his BRAIN...

http://i0.lbp.me/img/ft/700c05e876bc63c532ae09ea7b79231ec966a127.jpg

We'll put a controlinator in there. Now, open up the Controlinator microchip. For this example, we'll just have him simply LOOKING left and right alternately; to do this, I grab a 2-port selector and a direction combiner and wire them up like so:

http://i9.lbp.me/img/ft/309f30091fd0b542255d47a7c9624ac266d3855c.jpg

Okay, so now we have that, let's see if we can find a way to make the selector choose left and right alternately as a timed action. I do this by first of all placing a timer (mine's set to 2 seconds, but the time is entirely up to you) and wiring it's output to it's reset input.

http://i7.lbp.me/img/ft/0578bf2071f470548954ae2292a129d04881ed85.jpg

This means that as soon as it reaches the end of it's own count, it will output a very short signal before it resets itself and starts again, going in an infinite loop!

Okay, so now we have that, we need to wire that output to the cycle input of our selector; what this achieves is a constant toggle between our two selector states, which are in turn linked to the positive and negative inputs of the Direction Combiner.

This works because in LBP, left and right are determined by negative and positive signals, respectively.

So then all we need to do is wire the direction combiner into the left/right input of the Controlinator head movement:

http://i5.lbp.me/img/ft/e65cacda0487416e6d6740fe95857aa8488c7994.jpg

So if you were to collapse everything now you'd have a fairly good illusion of a Sackboy "looking" left and right in alternating fashion. But this is only SOME of the illusion.

Now we need to define those pesky terms, left and right! To do this, we now need a couple of new components, so make some more space on your microchip and slap down a direction splitter and a player sensor.

Wire up the Direction Combiner to the Direction Splitter you just put down, and you'll notice that when the Combiner has its' positive input lit up, the positive output of the Splitter also lights up, as is the case with the negative. This is the first step into setting up our direction detection.

So, then set your player sensor to an angle of 180 degrees, angle snap it 90 degrees to the right, place it close to the positive output of the splitter (just above it), copy and paste this, turn it around in the opposite direction and place this one just below the negative output of the Splitter.

(I also set both of them to "same layer" detection, but this is entirely up to the creator.)

If you were to go into the player sensor settings now, there should be one semi-circular trigger radius facing to the right, and one to the left, both coming from the direct centre of the sackbot. This along with our Direction Splitter is how we're going to help define left and right to the sackbot.

But it's not done yet! Pull out a two port AND gate, and make two of them just to the right of the direction splitter.

http://i4.lbp.me/img/ft/894e5ce05f0f3eda20e1b484a168d56ae7420bb0.jpg

Here's what's going to happen: given that we understand the way the game interprets left and right, it's actually a fairly simple matter to give the illusion the sackbot cannot see the player if it is facing the wrong way.

So we need to tell the logic "If the Player is within the player sensor radius AND the sackbot is looking at him then X will happen".

We can determine what "X" is in a minute, but for now let's wire things up accordingly; Take the right-facing player sensor and wire it into the first AND gate. This is the first condition for the sackbot detecting the player, and also forms the first part of our logic instruction, "If the Player is within the player sensor radius AND".

Now we need to tell the sackbot whether or not he's facing right. This is where the Direction Splitter comes in handy because the game interprets "right" as a POSITIVE SIGNAL, so we need to take the POSITIVE OUTPUT (the output with the 'plus' sign) of the Direction Splitter and wire it into the same AND gate that our right-facing player sensor is attached to, making this the SECOND condition for our AND gate and forming the next part of our logic instruction "AND the sackbot is looking at him".

Do the same thing with the left player sensor and the NEGATIVE OUTPUT (minus sign) and we've now set up some very straightforward logic to determine left and right detection in our sackbot.

Now all that's left is to determine "X", which could be anything! For purposes of this tutorial i've simply made him Livid when he sees the player

http://i0.lbp.me/img/ft/a50c3056d4bb6ceb52e448bfa758d151b3527018.jpg

and Ecstatic the rest of the time

http://i7.lbp.me/img/ft/797364788cf64c3d092d9aa4050cd4d3b9919cf6.jpg

but you can set up whatever behaviour you need for your level.

I simply made an OR gate wired to the appropriate behaviour and both AND gates wired to the OR. Simple!

http://i8.lbp.me/img/ft/7b89a3af6b19740fa9144cc40d92fc50b9b8c80b.jpg

But we don't have to stop there! Let's make it so that we can actually take advantage of him when he's not facing our way!

All we need to do is say to the logic "If player is within the left player sensor AND the sackbot is facing right AND the player grabs him, X will happen". Once again, "X" can be defined later, but for now slap down two 3-port AND gates.

Now this is where wiring gets a bit messy!

Connect the left player sensor to the first condition of the first AND gate. "If the player is within the left player sensor AND" is now formed.
Now connect the RIGHT (positive) output of the Direction Splitter to the second condition of our 3-port AND gate. "AND the sackbot is facing right" is now defined.
Lastly, stick a grab sensor down and hook it up to the last condition to define "AND the player grabs him".

Now the same for the other AND gate, namely the RIGHT player sensor, LEFT (negative) output of the Direction Splitter and of course the grab sensor!

It should look something like this:

http://i2.lbp.me/img/ft/90265a4291955327cc0791cc07de84a7b551d3be.jpg

Once again i'll leave you to define "X", but I hope this tutorial is of some small value.

Here are a couple of examples of what i've set up:

http://id.lbp.me/img/ft/8dd0f354732f0e49a0ad225ef22682283d93b486.jpg

http://ie.lbp.me/img/ft/adeaa27cd11e73393d1df8fa9b45bbbb7737568c.jpg

It's actually very simple in concept, and even execution is remarkably easy. I have a more advanced version of this tucked away in my captured objects, but I just thought i'd walk you through the basics of the logic behind it first.

If you have any problems don't hesitate to PM me and i'll get back to you forthwith!
2011-11-03 10:19:00

Author:
RainbowtipsFort
Posts: 144


And this is beginner-intermediate?! Well with my poor logic, any logic impresses me. Does this work if you are above the enemy, shuffling along a ledge using R1 or walking past above and below?2011-11-03 11:58:00

Author:
LittleBigDes
Posts: 920


It depends on the context it's used in, but I am using a more refined version of this in my upcoming level. This tutorial is simply a way for people to understand how direction works in LBP and how it can be applied to create a gaming mechanic insofar as enemy A.I is concerned.

Perhaps putting beginner IS a bit of a stretch, but I don't think it's anything beyond the intelligence of the average LBP player!

I hope not...
2011-11-03 13:49:00

Author:
RainbowtipsFort
Posts: 144


Nope, it's a good tutorial. But I don't have a level that would put it to use at the moment. Have you played the Hansel and Gretalbot series? As this has a stealth section in it with guards patrolling. May give you more ideas. Can't wait to see how you use this in your upcoming level.2011-11-03 14:06:00

Author:
LittleBigDes
Posts: 920


Haven't played that one actually. Will have to give it a go!2011-11-04 14:21:00

Author:
RainbowtipsFort
Posts: 144


Nice, straightforward tutorial; I'm no EE, but the logic looks really solid and well thought-out. Good job explaining the reasoning behind the logic as well, that should help a few people, I assume. Well done 2011-11-07 08:23:00

Author:
EvilWuun
Posts: 152


I wanted to reply but the site lagged the other day, so I'll post now. I liked that idea, but I thought about how you could add to it. Place 3 blocks of holo the size of a sackbot's hitbox (around 2x3 small grid squares), one on each layer, and glue them together. Make them invisible and make them follow the bot. Now place a tag on each block, with different labels. Next, make the bot detect which holo-block he is standing in, telling him on what layer he is. Finally, make a player sensor radius around the robot for any direction around him and any layer. Now using some AND gates and OR gates, you can make the bot go in alert mode if the player is in front of it, but not if it's behind it. Combined with the head movement, you could make the bot turn his head gradually, and when he looks in front of him he doesn't see behind him. Then make him patrol around

If you have too many sackbots using this, instead of having following holo, you could use global tag sensors set to same layer, and place a tag of each type somewhere in the game. The funny thing is that my next work is a run and gun, so that would work nicely in it by giving a gun to sackbots (will the player have a gun? not sure anymore)
2011-11-10 03:17:00

Author:
Unknown User


I wanted to reply but the site lagged the other day, so I'll post now. I liked that idea, but I thought about how you could add to it.

I love your idea, but remember this is supposed to be a beginners' tutorial explaining how direction detection would work in this context! I didn't want to get bogged down in layers, but I do like your suggestion a lot, and it would work very well as a gameplay mechanic.

Thanks for taking the time to forward it!
2011-11-10 07:51:00

Author:
RainbowtipsFort
Posts: 144


Oh, I didn't mean to add it in, I just meant that this logic is extendable and powerful. I just never would have thought of rotating the head. So thanks to you for giving me ideas!2011-11-10 22:22:00

Author:
Unknown User


Oh, I didn't mean to add it in, I just meant that this logic is extendable and powerful. I just never would have thought of rotating the head. So thanks to you for giving me ideas!

Well that's no problem whatsoever! I hope you get some mileage out of it! I might try your idea as well, as I never really thought about layer-based detection, although it would have been the next logical step.

So thanks to YOU!

2011-11-11 08:02:00

Author:
RainbowtipsFort
Posts: 144


Very well done tutorial! There are still a few things that I would add in like once the sackbot see's you it doesn't look away and glares at you until you go away or copy and paste the Right/Left sensors and redo with Up/Down but that's just me. I'm not saying it's bad that you didn't add those in, I understand that this is a basic tutorial. Great job though. I find this tutorial very helpful because there is so many different ways that more advanced creators can expand on what you have. Helped out a lot! Thanks!2011-11-16 02:58:00

Author:
Wolffy123
Posts: 406


No problem! Like I said, I have a far more advanced version of this logic tucked away in my captured objects and those issues that you mention are in fact resolved; I was going to expand on this idea with "noise detection" for my next tutorial, but perhaps I should cover these few small issues first. Thanks for your kind words!2011-11-16 08:31:00

Author:
RainbowtipsFort
Posts: 144


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.