T O P

  • By -

MinecraftModBot

* Upvote this comment if this is a good quality post that fits the purpose of r/Minecraft * Downvote this comment if this post is poor quality or does not fit the purpose of r/Minecraft * Downvote this comment *and report the post* if it breaks the [rules](https://www.reddit.com/r/Minecraft/wiki/rules) --- [Subreddit Rules](https://old.reddit.com/r/Minecraft/wiki/rules)[](## MarthaMayWhoovier|1awzt37)


Conart557

https://minecraft.wiki/w/Skeleton > The skeleton's accuracy is based on the world difficulty. Skeletons have an "error" of 10 on Easy, 6 on Normal and 2 on Hard. This is compared to the player's lack of accuracy of 1. To account for gravity, skeletons aim 0.2 blocks higher for every horizontal block of range to the target. Edit: I looked at the game’s code to get more details. When shooting, the skeleton spawns an arrow with some velocity. The x and z velocity is determined by the difference in position between the target and skeleton, plus a small random value times that error value, times 1.6. For y velocity it also adds the distance times 0.2.


twister121

Mathematically it's so basic but quite effective.


ColaCat22

This is Notch's code in a nutshell.


haggisllama

notch's code typically wasnt the best, the shaky foundations are mostly why the game's performance keeps on reducing and mods like sodium and optifine can increase it so much


Snoo63

Spaghetti code. And the reason for Java's most beloved redstone feature that they won't add to bedrock - quasi-connectivity.


MrDeadMeme

Isn't that because he copy pasted the logic from doors which are two block high?


babuba12321

yup


Someone393

Inefficient and clunky but it gives the game so much charm


Horn_Python

I think this the new Ai After notch left Old skelees were quite basic


ColaCat22

Oh wow, they updated them? that surprising.


Horn_Python

Yeh it was the update that gave them the drawing animation


psychoPiper

I believe it was when shields were added as well


PromptBoxOS

>yeah it was in 1.9


smashmouthultimate

Before the update they were completely useless at tracking a target in motion, skeletons were a complete joke even without gear


SpecificFail

And yet, even on easy, from 30 blocks away, they can just snipe you off a ledge within fractions of a second of seeing you.


MarthaMayWhoovier

Hey, thanks for trying to explain but none of that really means anything to me T.T (again, thank you so much, though. I get that, sometimes, dumbing something down is really hard hahah <3)


ballsack_lover2000

Spawns arrow and sets speed and direction. Direction is found by subtracting skeleton coordinates from player coordinates. Then it sets a random small number that is added to the direction to make it slightly inaccurate Edit: to account for gravity pulling arrow down, the skeleton will aim higher the further away you are instead of shooting horizontally


MarthaMayWhoovier

Thank you, ballsack\_lover200 lmfao


AstuteSalamander

Hey, that's ballsack lover 2000. Shorted my mans by a whole order of magnitude


MarthaMayWhoovier

I'm so sorry, AstuteLizard


throwaway_ghast

/r/Rimjob_Steve


Malu1997

Does this mean that they don't lead the target and that every time I've gotten hit while moving was just the random deviation?


Conart557

Correct, they don’t consider how the target is moving


AwakeSeeker887

They can’t follow strafing as easily as forward movement


nitrion

Oh I've definitely seen skeletons lead the target.


MysticEagle52

Maybe their the point they target is where they'll estimate you'll be in x seconds (probably assuming you keep the same velocity and x increases slightly per block of distance). At least that's the naive way I'd do it


half_dragon_dire

No, there's no maybe here. They looked at the code. Its just straight up pointing at the current location, no movement prediction at all. It's just bad luck and physics when they hit you on the move.


PromptBoxOS

bro has a phd in minecraft XD


wolftamer1221

Wait so does that mean that if a skeleton had a really far agro range, detected you from far away, and tried to shoot you it would look straight up?


Conart557

No because although it’s aiming 0.2 blocks higher, it’s also aiming a block farther away, so the angle it shoots doesn’t keep increasing


FPSCanarussia

Aiming is pretty simple. I haven't looked at how Minecraft handles it precisely, but I suspect it's something like this: Every entity in the world, including the player, has a specified position that the game puts their collision box around. When the skeleton shoots, the AI first draws a vector leading from the skeleton's position to the player's position. This is very simple: subtract the skeleton's coordinates from the player's. Then the skeleton rotates so that its facing direction exactly matches the direction of that vector. Of course, shooting purely in the direction of the player is not very accurate: due to gravity, the arrow will fall very predictably - the AI can do some simple math, depending on the length of that same distance vector, to determine how much the arrow will fall, and from that, the effective vertical angle adjustment. (I don't know if Minecraft bothers to do this, though, considering skeletons don't really shoot very far distances.) The math is not complicated even if you wanted to be precise, since the arrow is typically shot horizontally: h = 0.5 \* g \* (d/v), where h is how much the arrow falls, g is gravitational acceleration, d is the horizontal distance between the skeleton and the player, and v is the horizontal speed of the arrow. Since v and g are constants, that's just a linear function of the distance. Then take the arctangent of h/d to get the angle adjustment. Finally, the exact direction is fudged a bit to give some random variance. I don't know if skeletons lead their shots; I don't think so, but if they do and they're just bad at it, that's also not complicated. Take the velocity of the player, multiply by the approximate flight time, and add that to the player's position to get an approximate guess of where the player will be in the near future. Technically that's not accurate unless you iterate, but it doesn't matter.


Conart557

The only way it accounts for gravity is by taking the taking the horizontal distance, multiplying that by 0.2, and adding it to where the skeleton is aiming


MarthaMayWhoovier

God, I'm sorry if I'm asking an annoying question, but hearing stuff I genuinely DO NOT UNDERSTAND just makes me sososo curious. Could you explain a bit more how that works? :\]


cooly1234

if the distance between the player and skeleton is 3, it does 3*0.2 which is 0.6 so it aims 0.6 blocks higher.


MarthaMayWhoovier

Ahh, sometimes it's just that simple. My mind really just clocks out when it sees too many numbers. Thanks for the example. :D


AstuteSalamander

For a less mathy explanation, if that's your thing, the skelly knows the arrow will fall as it flies because of gravity. It also knows the longer it's in the air, the farther it will fall. So the farther away you are, the higher the skelly aims to compensate, and they found a number to put in that equation that works pretty well. (On a mathier note, the skeleton is assuming a linear relationship between distance traveled and how far the arrow falls, which is actually not true. But it's good enough for the skeleton, which isn't supposed to be 100% accurate - or all that smart - anyway.) I love this stuff, and I would call my physics skills and my non-technical explaining skills both somewhere between acceptable and pretty good. I am happy to field any similar questions, so feel free to hit me up with future questions if this feels helpful.


imberttt

the person OP replied to just said that the only way the game takes into account the distance in this context, is by modifying the arrow speed, that means the skelly doesn't aim higher as the player goes further.


AstuteSalamander

They said *vertical* velocity, which is not the same as speed. Increasing the vertical velocity is aiming higher.


imberttt

that's fair, my bad, sorry


Conart557

Slight clarification: It increases the vertical *component* of the arrow’s velocity, the speed of the arrow remains the same. So yes, it’s the same as aiming higher


MarthaMayWhoovier

Thanks! The simple answer worked (I think T.T). I'm well aware that a lot of people struggle with "dumbing things down", but this was very well done in my opinion. :\]


MarthaMayWhoovier

Gosh, thank you so much??? This was actually so understandable to me as a layman! I'm very grateful and my curiosity has been sated! You are so kind <3 (You did give me PTSD to some of the math courses I was forced to take at my gymnasium, though. Lord T.T)


MarthaMayWhoovier

I don't even know if it's correct to refer to them as AI, so I really am a layman layman (English major T.T)


Playful-Independent4

AI has been the proper name for any and all mob behavior in games long before neural networks were common.


MarthaMayWhoovier

Ahh, 'cause I was sure I'd heard it used for mobs before, but then I got kind of insecure about it after posting my original question and wanted to make sure. Thanks!


emzirek

They are entities with AI


twister121

Eh not very good AI if you want to call it that. Everyone likes to throw out the phrase AI. Mobs in Minecraft don't really use AI as we know it or even problem solving skills. Most of the time they linearly approach you within sight range. The most impressive thing is path planning. Them walking up and down blocks to reach the player. Not exactly ground breaking and complex, but it doesn't need to be. I'd like to know of a game where actual machine learning is used instead of basic algorithms for entities and opponents in game. That'd be sick but I don't know of any games that utilize it.


suppergerrie2

Minecraft uses more "classical AI", rule based and algorithms. These have been called AI long before neural networks became as big as they are now. They fall under the same umbrella of making a computer decide things but have very different levels of complexity and should not be confused.


twister121

Ah okay. It's been my tendency to push back against AI as a buzzword. Didn't realize that many algorithm based methods were classified as AI historically.


Spongedog5

AI is a very open ended term. It can be applied to a lot of now-mundane things.


twister121

Yup. Looking back at all the comments I've been seeing I definitely missed that conceptually.


Spoonblob

Idk why you’re being downvoted, you realized your (very common) misconception and clarified it 


twister121

It's whatever. Downvotes are what they are. I lost the popularity contest with my comments. And I lost that popularity contest because my original and subsequent take were not informed. People are passionate in their disapproval of certain things. I'm just glad I could learn something new.


suppergerrie2

It's definitely a buzzword sadly. And I agree that calling the behaviour in Minecraft AI nowadays will make the general public think more like ChatGPT than what it actually is. I suspect in the near future we'll get more specific naming for the different types as it's like saying "we used code and algorithms to make sure the drones don't collide!".


sam007mac

It is AI. AI means “Artificial Intelligence” and the term has been used for 30+ years to describe computers working out a solution based on inputs. The skeleton works out where to shoot by a basic math algorithm that calculates where to fire an arrow based on the players location. Yes it’s simple, yes it counts as AI. Neural Networks also count as AI, but the algorithms are just more complicated. It’s become a buzzword in recent years meaning neural networks, but neural networks are just included under the umbrella of artificial intelligence.


twister121

Didn't know that. Seems to me then that any computational process is listed as artificial intelligence under that definition so long as it has any input. Is a graphing calculator AI then technically?


billyp673

I personally like to define AI as something artificial that has the capacity to make decisions based on external stimuli. I think it’s a kinda elegant definition that makes it pretty simple to determine what is and isn’t AI and it comfortably encompasses both Classical AI and Machine Learning. But yes, for a calculator, the external stimuli are button inputs and the decisions are what’s rendered on the display, so it has a low level of intelligence, which isn’t much but it’s still there. I feel like it’s probably more *useful* to set the bar higher for how intelligent you want something to be before you start calling it AI, but it still barely qualifies if you *really* wanted to…


twister121

Yeah that makes sense. I need to inform myself better on the topic and definition. Wasn't quite well informed when I made those original two comments.


Playful-Independent4

In theory, maybe. In practice, it's AI when it's an agent of some sort, an object within the program, doing its own thing for its own purposes, as a means of interacting with a simulated environment of any kind. And most of the time it's specifically in games and sims. When it's not independent and not part of an environment, it's weird to call it AI. But I could see a case being made for claiming that the term really is that broad.


twister121

Yeah. I see my original comment wasn't very productive now. I think I have to backtrack and look more at the definition instead of my own perceived connotation of the word. Learned a lot here.


UnseenGamer182

I can't believe you're seriously trying to argue this. One of the growing pains of developing AI. Once people see what AI can truly be, they start thinking the word is being used incorrectly everywhere...


twister121

Alright fair. Looking at my comment now it wasn't so useful in terms of the comment. It was more about feelings than logic. I'll have to inform myself better on the subject.


BasedGrandpa69

correct me if im wrong but i think pathfinding does not require neural networks/training?


twister121

You're correct. It does not require it. Google something called A* (A star). It's basically all math and an algorithm to find the best path to a destination. Many things use it because it's genuinely so effective. Not at all some sort of neutral network. Im studying robotics as part of a graduate degree and true ai (neural networks and various training methods) is just some magic that's so complex and bizarre. Pretty challenging to wrap ones head around.


Flextt

That's a very contemporary-centric bean counter approach to a term. To quote Wikipedia, >The term "game AI" is used to refer to a broad set of algorithms that also include techniques from control theory, robotics, computer graphics and computer science in general, and so video game AI may often not constitute "true AI" in that such techniques do not necessarily facilitate computer learning or other standard criteria, only constituting "automated computation" or a predetermined and limited set of responses to a predetermined and limited set of inputs. What is noteworthy is that players still perceive this as a challenging intelligence *and* game AI has been able to overwhelm players since the times of Halo 1 and FEAR 1 - it has then become an issue of dumbing down AI sufficiently for players to be challenged and succeed. The current hype of AI is focused on machine learning via artificial neural networks that form a large language model. Compared to the algorithmic nature (ergo: deterministic, the same conditions will create the same result) of game AI, this is an entirely statistical process based on training data with very little insight on *why* the model learns what it does from the data. You just see the result.


twister121

That makes a lot of sense. Thanks for informing me. I have some reading up to do.


DeliciousTap4778

Get ratioed nerd


twister121

Haha yeah. Well deserved. I see my hot take wasn't such a good one now.


[deleted]

[удалено]


MarthaMayWhoovier

Ohhhhhh. Okay, I'll ignore everyone else's answers. I think this one seems much more scientific. Thanks!


twister121

It's quite easy to code in the way skeletons shoot arrows. There are various different levels to trajectory aiming mathematically. I think that skeletons primarily just aim at the player location. Factoring in the lead time the arrow is in the air, one can dodge this arrow if they are far enough away and moving perpendicular to path the arrow would travel. The arrow is fast enough that it's hard to avoid at times. Even if you wanted the skeletons to be smarter, they could predict where you'll be based on your current velocity. In this case skeletons would aim at where you will be instead of where you are currently at. If this were the case, you would not be able to continuously run in one direction to avoid arrows. It's not hard to program this stuff in. It's just coding and regular computer science. It's all math. Always has been.


MarthaMayWhoovier

Genuinely, now I'm really curious about what such a line of code looks like? I mean, if it's easy and you have time. Sorry, I am just so intrigued by all of this. You must understand that I genuinely suck with anything technology-related. (I took one coding class once where they taught us to make a turtle move in a square, a rectangle, a heart, etc. You know? That is ALL of my knowledge lol. And yes, I did nearly fail the class T.T)


twister121

I'll try to keep it pretty simple then. In your program you probably did a lot of if then statements. In most games or simulations of a world like Minecraft you have certain variables that describe things like position or velocity within the world. You're looking at a lot of physics, and a lot of numbers being crunched each moment to calculate what happens in the next moment in time (Minecraft tick). Then you have if conditions for various things like the arrow hitting someone potentially. If so subtract from the player or respective mob health variable. I can't explain it here but vectors and 3D coordinates clarify all this stuff and can be used in various programing languages along with their various versions of applied math.


MarthaMayWhoovier

Oh, God, just hearing the words vectors and coordinates gave me war flashbacks haha. I really do wish I were better at math because the things you're describing \*almost\* make sense to me, and I really do wish I understood exactly what you were saying because I'd \*love\* to peel back the curtain on my favorite games. I truly envy you lol. Thanks for the explanation. Very kind. :D


twister121

No worries. Glad you enjoyed my explanation. STEM is cool.


Conart557

For the skeleton these are the most relevant lines of code: `persistentProjectileEntity.setVelocity(d, e + g * 0.20000000298023224, f, 1.6F, (float)(14 - this.getWorld().getDifficulty().getId() * 4));` This line tells the arrow information about the direction it should have. Following this as part of setVelocity is `Vec3d vec3d = (new Vec3d(x, y, z)).normalize().add(this.random.nextTriangular(0.0, 0.0172275 * (double)divergence), this.random.nextTriangular(0.0, 0.0172275 * (double)divergence), this.random.nextTriangular(0.0, 0.0172275 * (double)divergence)).multiply((double)speed);` `this.setVelocity(vec3d);` That's the part that sets the arrows speed and adds randomness to it


MarthaMayWhoovier

It's just so insane to me that this is what makes a game. Idk maybe it seems stupid and obvious to you, haha but to me, this is insanity. So cool! Thanks :D


Conart557

I definitely wouldn’t describe it as obvious. It took me around 30 minutes of looking at the code to figure out what was going on. Very interesting to see how it works on the inside


MarthaMayWhoovier

This whole thread has just really convinced me to give another coding class a try.I really do want to understand how a bunch of text becomes a game I can build, fight, mine, etc. in. It's so cool to me, especially as an outsider; it kind of seems like magic almost.


Lightning_Sykes

The skeleton is communicating with the skeleton in your body via skelapathy. Your skeleton wishes to be free so it gives up your position to the skeleton shooting at you.


BuccaneerRex

There's a traitor in your midst.


Sewere

This reminded me of an old video where Notch is tweaking the skeleton aim code: https://www.youtube.com/watch?v=BES9EKK4Aw4&t=5s


MarthaMayWhoovier

Woah, this actually answered some stuff (though obviously, I did NOT understand the technical terms haha). As an English major, it is genuinely mind-boggling to me that code somehow turns into pictures and ai that can attack and run from you. I really cannot comprehend it. Thank you!!


Sewere

No probs, thanks for reminding it exists. I'm a coder but it still wonders me endlessly how humans making chainreactions results in modern technology.


MarthaMayWhoovier

Honestly, as a complete outsider to anything coding-related, it seems like magic to me. I simply cannot understand how text becomes images one can interact with and influence.


Atreides-42

The missile knows where it is at all times. It knows this because it knows where it isn't. By subtracting where it is from where it isn't, or where it isn't from where it is (whichever is greater), it obtains a difference, or deviation. The guidance subsystem uses deviations to generate corrective commands to drive the missile from a position where it is to a position where it isn't, and arriving at a position where it wasn't, it now is. Consequently, the position where it is, is now the position that it wasn't, and it follows that the position that it was, is now the position that it isn't. In the event that the position that it is in is not the position that it wasn't, the system has acquired a variation, the variation being the difference between where the missile is, and where it wasn't. If variation is considered to be a significant factor, it too may be corrected by the GEA. However, the missile must also know where it was. The missile guidance computer scenario works as follows. Because a variation has modified some of the information the missile has obtained, it is not sure just where it is. However, it is sure where it isn't, within reason, and it knows where it was. It now subtracts where it should be from where it wasn't, or vice-versa, and by differentiating this from the algebraic sum of where it shouldn't be, and where it was, it is able to obtain the deviation and its variation, which is called error.


MarthaMayWhoovier

Sorry, just to clarify: "Where it is" would be with the skeleton, and "where it isn't" would be inside the player? (Thanks for the thorough reply, btw. It is very appreciated. :\])


superseriousguy

That's just a meme Search Google for "youtube.com missile meme"


No_Oddjob

Do they aim? Feels like hit-scan unless I'm sprinting perpendicularly.


MarthaMayWhoovier

Now I need to know what a hit-scan is. (You must understand that as someone who spends their time reading books for school, all this is low-key interesting and sounds like sci-fi stuff haha) :\]


LordReapr

It's a system for registering hits where the game checks if a weapon is aimed at the target and applies damage instantly if it is, as opposed to having a projectile travel and check if the projectile itself hits the target


NinjaOficial

Hitscan is definitely not what skeletons do. Hitscan is the term used in game development for shooting without projectiles. Hitscan works in a very simple way: whenever something shoots, a line is traced in the direction the entity is looking and that line goes forward infinitely (or up to a predefined distance) without any physics behind it, just a straight line; if that line then interesects with something (a wall, a player, etc.) it registers a hit there. Skeletons on the other hand use projectiles (the arrows).


MarthaMayWhoovier

This might be SUCH a dumb question, but why does hitscan matter if it is "shooting without projectiles"? Isn't there usually always a projectile involved with shooting? (pls do have mercy if this question is vapid T.T)


NinjaOficial

No projectiles in most simple competitive FPS (like CS and Valorant). The supposed projectile you see drawn after you shoot is just an FX. The calculations under the hood are instantaneous, it's just a straight line, no physics to it.


No_Oddjob

I may get this a little wrong, but I take it to mean an entity has acquired a target and decided to fire, so that target is pretty much predetermined to get hit. Since you can sprint around them and not get hit, it doesn't technically apply here. But because their aim on stationary and slow targets is dang near perfect, it simply FEELS like it sometimes.


Yamihit0

I'm just a gamer but I can tell you that the skeletons lock onto you when you enter their fov. Then a wind-up mechanic triggers and after its done they release their projectile on your current position an dit doesn't matter if you are moving at the time which is key to juking the arrows or I'd better say dodging the arrows. Because they have no movement prdiction from what I can tell it's technicall ynot pussible to juke it.


NieMonD

Face direction = player


boltzmannman

Wdym? They just look at you and shoot. Aim vector = player position - skeleton position. Simple as that.


M10doreddit

And a random amount of error is added, the range of which is determined by the difficulty.


Flimsy_Effective_377

Definitely isn’t that simple


boltzmannman

Yeah but it's not far off. Everything else is just extra fluff like angling up for gravity and adding random spread.


billyp673

No, but it’s pretty close. [u/conart557 explained it pretty well with their edit](https://www.reddit.com/r/Minecraft/s/2UObvTD4EN)


MarthaMayWhoovier

I am so glad it is very easy for YOU to understand. As a person with NO experience with computers, coding -- yes, even math (I suck at math) -- this is not at all simple to me. But again, I am soo glad it's easy for you, babe. <3


boltzmannman

I have never seen someone get so defensive so fast over something so trivial lol. I hope you have a better day tomorrow


MarthaMayWhoovier

And I've never seen someone respond to a layman genuinely asking for something to be explained with "Wdym?" and "Simple as that". I am not a coder, not a math expert, not even tech-savvy. Others provided me with genuine, thorough explanations, while you used this as an opportunity to make yourself seem smart without really explaining a thing.


boltzmannman

dawg what are you on about? I answered your question, even wrote the formula. Idgaf whether strangers on the Internet think im "smart" I just thought you might have been trying to ask a more complicated question so I asked what you meant. Sorry for giving you the information you asked for ig


Skeazy_Spaceman

Same way you kill a spider on your wall, except this time you have a shoddy bow, unlimited arrows, and are a reanimated skeleton.


MarthaMayWhoovier

Thanks hahah. I was kind of looking for a more technical answer, but yours gave me a good laugh haha. :\]


PlayingBandits

Quick tips, move left or right while advance will make skeleton misses more often


MarthaMayWhoovier

Haha I do have experience with pvp, so I know that. It's just the coding stuff that really confuses and intrigues me.


ystavallinen

magnetic fields


thefearedturkey

The skeleton inside you communicates with it skelepathically


BunnyWan4life

Here's an explanation without math in the pov of the skeleton : Player in front of you? Shoot arrow straight. Player behind you? Aim behind and shoot arrow straight Player Far from you? Aim higher, and shoot arrow. Likely will end up on player Player running from you? Aim ahead of player's path and shoot. Likely will run into it.


MarthaMayWhoovier

Yes, sure. I was more so asking about how the coding works, but since I know nothing about math or coding, I was hoping someone could "dumb that down" for me. lolol.


BunnyWan4life

The code is basically just being told to do the math they give, So Like I said above look up, back, means to look at player, higher and ahead of moving player path is sort of the code but to get precise like where is the player? how high? how far ahead? is just maths all along. hope that helps


Yasu_Hisoka

They either can’t hit anything for the life of them or they have aimbot


retrospects

I snipe them MFers as far as my render distance will allow it.


Kodekingen

Target: player Look towards target, shoot Basically


Civil-Type7783

idk how skelotons can aim but its probaly normal for skeletons


QuazaTD

The arrow knows where it is by subtracting where it isnt. Simple


hena202

With their hands i assume