Pathfinding AI - Miner Mob
In this tutorial, I will be showing you the basics to creating your own pathfinding AI through recreating the miner mob from Clash of Clans and Clash Royale. If you are here for the commands rather than learning they are all at the bottom of the page.
The commands I will be using to achieve this are:
• Execute
• Summon
• Tp
• Kill
• Particle
Method / Explanation:
For this tutorial, please note there are so many different ways to pathfind and I am only showing one in this tutorial, so if this feels a lot more direct to my example and not very changeable that is why, although I will try to explain what you might want to change the best I can.
I am going to split it into 3 categories:
-Particle Effects
-Movement
-Targetting
I also recommend watching the video to see what it looks like before I explain it.
The commands I will be using to achieve this are:
• Execute
• Summon
• Tp
• Kill
• Particle
Method / Explanation:
For this tutorial, please note there are so many different ways to pathfind and I am only showing one in this tutorial, so if this feels a lot more direct to my example and not very changeable that is why, although I will try to explain what you might want to change the best I can.
I am going to split it into 3 categories:
-Particle Effects
-Movement
-Targetting
I also recommend watching the video to see what it looks like before I explain it.
If you watched the video, you would have saw that the pathfinding is a little jumpy. This is because this system works in the main 8 directions only so not 100% accurate. I did this because the Miner from Clash Royale is a bit jumpy but theoretically you should be able to make it more accurate if you wish. I will explain how later. But first lets start with how it works and how to create it.
Before Anything
Before anything we need the Miner mob or a mob to pathfind. For mine there are two versions of this mob, one is an invisible armor stand underground:
/summon armor_stand ~ ~-1 ~ {NoGravity:1b,Marker:1b,Invisible:1b,PersistenceRequired:1b,CustomName:'{"text":"Miner","italic":false}'}
And one is a zombie with a miner helmet which replaces the invisible one when it reaches it's victim. You do not need two mobs you may just want one and then have something else happening when it reaches it's victim but for mine I made it kill the invisible and replaced with something else which could actually damage.
/summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
Both of which I created with, you guessed it! McStacker, the summon generator. I am not going to talk about the second mob much as it just had it for an end to the system but just keep in mind if you want to attack them instead of changing to a zombie like mine you want to change your event later to:
/effect give @e[distance=..2] minecraft:instant_damage
Or something along those lines but I will remind you when this comes into play, we don't need any of this right now except your first/only mob.
Before Anything
Before anything we need the Miner mob or a mob to pathfind. For mine there are two versions of this mob, one is an invisible armor stand underground:
/summon armor_stand ~ ~-1 ~ {NoGravity:1b,Marker:1b,Invisible:1b,PersistenceRequired:1b,CustomName:'{"text":"Miner","italic":false}'}
And one is a zombie with a miner helmet which replaces the invisible one when it reaches it's victim. You do not need two mobs you may just want one and then have something else happening when it reaches it's victim but for mine I made it kill the invisible and replaced with something else which could actually damage.
/summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
Both of which I created with, you guessed it! McStacker, the summon generator. I am not going to talk about the second mob much as it just had it for an end to the system but just keep in mind if you want to attack them instead of changing to a zombie like mine you want to change your event later to:
/effect give @e[distance=..2] minecraft:instant_damage
Or something along those lines but I will remind you when this comes into play, we don't need any of this right now except your first/only mob.
Particles
Anyway I will start of with the easiest part. The miner mob is just an invisible armor stand in the ground for me so to give it a look I executed from it (Which I named miner) and added a particle effect. If you do not know much about selectors, I recommend checking out this tutorial here. This is obviously entirely optional. However it can really improve the look of your mob.
/execute at @e[type=armor_stand,name=Miner] run particle item dirt ~ ~ ~ 0.1 0.3 0.1 0.01 10 force @a
Anyway I will start of with the easiest part. The miner mob is just an invisible armor stand in the ground for me so to give it a look I executed from it (Which I named miner) and added a particle effect. If you do not know much about selectors, I recommend checking out this tutorial here. This is obviously entirely optional. However it can really improve the look of your mob.
/execute at @e[type=armor_stand,name=Miner] run particle item dirt ~ ~ ~ 0.1 0.3 0.1 0.01 10 force @a
This particle effect is called item and it can have the look of any block. After putting item just put the block id of the block and it will work.
Alternatively you may want a different particle effect instead of 'item' or maybe not one at all as your mob is not invisible. If you want a different particle effect, here is the full list of them.
Alternatively you may want a different particle effect instead of 'item' or maybe not one at all as your mob is not invisible. If you want a different particle effect, here is the full list of them.
Movement
Now for how it actually pathfinds. As you know armor stands have no pathfinding AI as they don't walk around or chase players etc. However this can be fixed by creating our own AI with commands.
The pathfinding I will be using involves executing from your mob and summoning invisible armor stands on every direction of the armor stand, this is why it only pathfinds in the main 8 directions. It will then execute from the victim and teleport the miner to the armor stand that is closest to it then kill all the armor stands and repeats this process until it reaches the victim.
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~-0.2 ~ ~0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~0.2 ~ ~-0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~-0.2 ~ ~-0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
etc.
To make it more accurate, here is where you would add more directions or make them summon closer to the mob would also make it be more accurate however make sure your armor stands all have the same name and all be the same distance to the main mob (Our miner)
These armor stand summoning commands should be in a repeating clock so they activate every tick.
HOWEVER WARNING: Don't have them on until the rest of the commands are set up! This is because we have not created the teleporting, killing and repeating process in targeting yet so it will just constantly create armor stands and lag you out.
We are now set up to pathfind! All we need to do is decide who it should target.
Targeting
For those who are still confused how this is going to work here is a diagram to help visualize it.
Now for how it actually pathfinds. As you know armor stands have no pathfinding AI as they don't walk around or chase players etc. However this can be fixed by creating our own AI with commands.
The pathfinding I will be using involves executing from your mob and summoning invisible armor stands on every direction of the armor stand, this is why it only pathfinds in the main 8 directions. It will then execute from the victim and teleport the miner to the armor stand that is closest to it then kill all the armor stands and repeats this process until it reaches the victim.
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~-0.2 ~ ~0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~0.2 ~ ~-0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
/execute at @e[type=armor_stand,name=Miner] run summon armor_stand ~-0.2 ~ ~-0.2 {CustomName:"{\"text\":\"Locate\"}",Invisible:1}
etc.
To make it more accurate, here is where you would add more directions or make them summon closer to the mob would also make it be more accurate however make sure your armor stands all have the same name and all be the same distance to the main mob (Our miner)
These armor stand summoning commands should be in a repeating clock so they activate every tick.
HOWEVER WARNING: Don't have them on until the rest of the commands are set up! This is because we have not created the teleporting, killing and repeating process in targeting yet so it will just constantly create armor stands and lag you out.
We are now set up to pathfind! All we need to do is decide who it should target.
Targeting
For those who are still confused how this is going to work here is a diagram to help visualize it.
Imagine our gold block as the miner / your mob and the diamond block to be it's target.
Imagine these orange wools to be the armor stands from movement. What we have just done is every tick it creates an armor stand on each side of it.
When we execute from the victim, we want to kill all the armor stands except the closest one.
If we do:
/execute at @p run kill @e[name=Locate,limit=7,sort=furthest]
It will kill the 7 furthest away locate armor stands then if we do:
/execute at @p run tp @e[type=armor_stand,name=Miner] @e[name=Locate,limit=1]
/execute at @p run kill @e[type=armor_stand,name=Locate,limit=1]
It will teleport to it and kill it.Then as we put it all in a repeating clock it will happen every tick therefore it will keep moving / pathfinding. Note that I put '@p' this means I set my target to be players. If you wanted it to be Villagers for example you would do:
/execute at @e[type=villager] run kill @e[name=Locate,limit=7]
/execute at @e[type=villager] run tp @e[type=armor_stand,name=Miner] @e[name=Locate,limit=1]
/execute at @e[type=villager] run kill @e[type=armor_stand,name=Locate,limit=1]
This system has no ending so that's why I made it come out of the ground if you want to do that too, put this command in front of your targeting commands:
/execute at @e[type=armor_stand,name=Miner] if entity @p[distance=..1] run summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
/execute at @e[type=armor_stand,name=Miner] if entity @p[distance=..1] run kill @e[type=armor_stand,name=Miner,limit=1]
Or if you don't want it to come out of the ground but instead hurt them you can do this:
/execute at @e[name=Miner,type=armor_stand] run effect give @e[distance=..2] minecraft:instant_damage
This Tutorial is my most advanced one and was very hard to explain but hopefully you understood it all! Even if you think you understood it all I recommend checking your commands with mine below in case you missed anything! ~Blue
/execute at @p run kill @e[name=Locate,limit=7,sort=furthest]
It will kill the 7 furthest away locate armor stands then if we do:
/execute at @p run tp @e[type=armor_stand,name=Miner] @e[name=Locate,limit=1]
/execute at @p run kill @e[type=armor_stand,name=Locate,limit=1]
It will teleport to it and kill it.Then as we put it all in a repeating clock it will happen every tick therefore it will keep moving / pathfinding. Note that I put '@p' this means I set my target to be players. If you wanted it to be Villagers for example you would do:
/execute at @e[type=villager] run kill @e[name=Locate,limit=7]
/execute at @e[type=villager] run tp @e[type=armor_stand,name=Miner] @e[name=Locate,limit=1]
/execute at @e[type=villager] run kill @e[type=armor_stand,name=Locate,limit=1]
This system has no ending so that's why I made it come out of the ground if you want to do that too, put this command in front of your targeting commands:
/execute at @e[type=armor_stand,name=Miner] if entity @p[distance=..1] run summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
/execute at @e[type=armor_stand,name=Miner] if entity @p[distance=..1] run kill @e[type=armor_stand,name=Miner,limit=1]
Or if you don't want it to come out of the ground but instead hurt them you can do this:
/execute at @e[name=Miner,type=armor_stand] run effect give @e[distance=..2] minecraft:instant_damage
This Tutorial is my most advanced one and was very hard to explain but hopefully you understood it all! Even if you think you understood it all I recommend checking your commands with mine below in case you missed anything! ~Blue
Your commands should look something like this:
Particle Effects:
Movement:
Targeting ( Players ) :
/execute at @e[type=armor_stand,name=Miner] if entity @p[distance=..1] run summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
|
Targeting ( Villager ) :
/execute at @e[type=armor_stand,name=Miner] if entity @e[type=villager,distance=..1] run summon zombie ~ ~-0.5 ~ {CustomNameVisible:1b,IsBaby:0b,CustomName:'{"text":"Miner","italic":false}',ArmorItems:[{id:"minecraft:leather_boots",Count:1b,tag:{display:{color:3546628}}},{id:"minecraft:leather_leggings",Count:1b,tag:{display:{color:4530691}}},{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:4004866}}},{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Name:"Miner"}}}]}
|
You have completed my final resource course, congratulations! I hope you enjoyed them <3
Be sure to subscribe if you haven't already as this all took ages to make :p
Subscribe!
Be sure to subscribe if you haven't already as this all took ages to make :p
Subscribe!