Hey guys and welcome back today we have kind of like an intermediate tutorial this is like it’s not going super deep into the advanced topics but it’s something that everybody that works with raycasting needs so this is going to be mainly focused on Ray casting but I have A couple non-data pack tricks to show that I think are useful but I’m going to be showing them later in the video okay after that way the important stuff gets set first so I don’t forget it anyways so we’re basically going to be working on how to detect when you hit Something in a ray cast so when you shoot a ray cast line the line travels directly in the direction you’re facing and when it hits something it will stop and you want it to actually detect when it hits that or whatever it does hit so I’m going to pop into a data pack and I’m going to assume you know how to make data packs and I can I’m going to also assume that you kind of are familiar with how ray casting works so we’re going to go into hit boxes and again This one thing to note is this doesn’t have to be used for ray casting you can use hit boxes on anywhere it’s just ray casting is the best application of it it makes the most sense to use it in ray casting so we’re gonna hop into ray and close some other Things and delete all this okay so we have a fresh function file now as you might know with ray casting you just do execute positioned carrot carrot carrot one run function and you have to play the one that you’re in so hitboxes slash ray and that would be how you do a basic Gray cast with no complexity added and this would just travel until it reaches the edge of the world or play sixty five five thirty five commands probably hits the edge of your loading render chunks first but it depends on how big you are under distances anyway so now to see What’s going on we’re going to add a particle called end rod because I think it’s kind of cool or baby crit crit is the one that I prefer honestly and we’re only going to make one of them stationary so now we’re going to reload and we need some way to trigger this you Could put it in the main function but I’m going to just use a command block for the hell of it because why not so we’re just going to do execute at a run function test hitboxes ray and once I play that I’m going to lack but you’re Going to see this ray coming out of my feet so now we’re going to have to see this to make it out of your eyes you have to do anchored eyes and just like that you’re starting to yeah let’s see anchored eyes okay let’s go ahead and Add in as at a because it probably is thinking yes there you go it needs to be as because the anchor deals with the command player’s eyes okay so this is now shooting something out of my eyes and this videos already demonetised alright so we want to advance this so First off we want to say if block air so if the block it’s going to go into is air then play it and doing this will make it a lot faster and less likely especially if I look down because it’ll just stop and not go through the ground Okay so now we’re going to deal with the actual hit boxes so we need to actually detect something so there’s a couple cool efficient ways to do this that I’ve learned and through the through the years but we’re going to cover the first which is the most powerful hit box so This is execute as a TD x equals zero so the x equals zero sees when you have interacted with an entity’s actual hit box not not the same as distance so that I’m going to briefly talk about that so distance when you use distance it’s kind Of like it picks in a radius like a spherical radius and it tries to select the entity that is in the radius based off of their origin my origin is right at my feet now DX is seeing if something is within that many blocks in the X Direction if you say DX equals zero you’re just checking if something is in this block here if I was to play it right here it would just say is somebody in this block here DX equals zero but the trick to this is that it when it is checking if somebody’s in the block It bases it on their actual hitbox so if my arm is in the block it will probably trigger because it’s bait my hitbox is my arm so it’s different from distance now since we’ve picked one and we’re saying as so now it the person when we Read anytime later that we say @s you’re referring to this entity that it found inside hitbox so now you’re going to oh now you’re going to say positioned negative 0.99 negative zero point nine nine negative zero point nine nine and you can change this to be more accurate 0.99 is going to be like a pretty accurate box here around the player but if you did like zero point seven you’re going to give some cushion room to detect whatever this entity is which you might want to do for some kind of a PvE scenario you usually want to have a Bigger hitbox okay so you’re moving so we’re saying okay we saw something in this square now we’re going to move backwards like back here into this square okay and then you say if entity at SD x equals zero okay so now you’re saying if are you still in the square if You’re still in the square then you have hit their hitbox because it’s within that point zero one range so you basically say did I hit the hitbox all right now let’s move back and do the same selection and if the two selections overlap then like if it finds them in Both then that you can say you hit it so we’re going to do effect give is glowing one okay and now the last thing that we need to do here is also specify type equals player and once we do that now we can start to actually test our hitbox to See how good it is so we just want to add one more thing here so we’re going to put this in here and we’re going to do effect at E effect clear at E glowing so now anytime something’s not in the range it will just turn it off so I’m gonna summon an Armor stand type reload and let’s test this so you can see as soon as I hit the armorstand it starts glowing and this credit article starts to get in the way because it’s so big but you can see that it works with the actual hitbox if I hit The right at the right when I get towards the center and the arm stands are kind of weird like that but if we go ahead and trap a villager somehow with some fence it’s better but our stands are kind of weird they’re their own their hip boxes are strange So summon villager and you’re gonna see just how accurate this is as soon as oh the fence isn’t the way as soon as I look at his actual hitbox like even just his arm it’ll trigger pretty much of course certain parts of the actual model are not considered part of the hitbox But it’s beside the point this is a very accurate hitbox and it works for any size it works for spiders it works for anything so that’s this one is super useful but what I like to do is I actually actually like to do a conjoint system because again sometimes You want to detect if you specifically hit the head so let’s go ahead and do two things so first this is a part of the efficiency stage so this hitbox detection lets you see if you’re roughly over on top of the entity right but now you can do play a separate function so This will keep your raycast command having minimal commands in it it only has three which is pretty good that’s going to be very efficient so we’re gonna do hitboxes slash hit and then you’re going to say test and then another thing to do is you can do unless Entity etai equals well I wouldn’t do that I’ll go over stopping the Ray later but it’s there’s some of the efficient ways to stop it so let’s go into hit and now we know that we hit something and we know we’re positioned back here so let’s Go ahead and position back to where our cursor is right it’s just like let’s just fix it we’re basically just cancelling out these two commands so now we’re back where the trigger thingy hit it where the raycast hit it so now you can such a detect like if you hit the Head so these kind of hit boxes are more dependent on like you find tuning things and then they also are mob dependent so the other one is good for general but if you want to detect what specifically where you hit something like the head and stuff then you need it for specific Types of mobs so like zombies have a different location than spiders and stuff like that okay so just for you guys I decided to pull this out because I’m kind of close on time so let’s just say type equals villager you can create like a entity tag type I did here I Called it target and that’s anything that you’re allowed to hit and then we’re just going to say so this has three different modes so if you go to the since we’re using distance the origin is at its feet right so we have to position our cursor down 1.7 see if We see its feet within a radius of 0.35 if we do then we have hit the head so let’s imagine that let me disable this let’s imagine that it lands right here we’re going down 1.7 that’s pretty far down that’s pretty close to the feet do We see the feet yes now let’s imagine we hit its arms 1.7 is going to be below the ground so it won’t be close to the feet so it’s kind of like you’re shifting everything down and then seeing if you’re still hitting the entity we’re after shifting so let’s go ahead and Just use the head one but you can see what these values are this is good for head body legs but dumb they’re not perfect so let’s go ahead and do effect give s glowing one one sure okay and then let’s go ahead and throw on a stopping condition because some people Find this confusing or difficult we’re just going to do scoreboard players set range s range is zero and we’re going to add a range condition if score a test range matches one and then we’re going to remove one range per iteration it can’t be is cuz is is the entity will Just do at P for now but you can figure out how to make it multiplayer friendly by tagging people before they play the raycast so we’re just going to again go ahead and add one of these here and add why these there and then scoreboard players set at a Range 100 there is a scoreboard range so when I hit reload you’re gonna see that my cursor does not quite go as far and I can mess with this value to say say 20 and it’ll only go 20 blocks so you can actually see the end there kind of and Now you can see I hate these fences let’s just go ahead and get rid of them so you can see nothing happens until I kind of reach his head you can see him start glowing what I’m looking at is head but again like there’s some issues With this air thing and it’s not like perfect so but you can see when I hit his head roughly it will start glowing within a certain range and it will actually stop after it hits his head so you’ll see it’s just like it’s hard for Me to show this but since the range gets set to zero it kind of stops the cursor after it hits him see yeah you can kind of see it’s not going through anyways so that’s pretty much it you can mess with some of the values you can mess with the 0.35 to make it more or less easier to detect and you mess with the 1.7 again as well at the same time and then you also can mess with these 0.99 values to make it a bigger or smaller regular hitbox so that’s the video on hitboxes I’m not gonna cover really anything else It’s mainly just this fine tune and then using this glowing effect really helps you figure out where your hip boxes and how it works of course you want to do data merge and CIE type 0 equals 1 no there you go so I don’t want them to Move so yeah you can really like kind of tune and see where your hip box is so this is just what I found to be useful for mine but you can figure out for yourself what yours is and then another trick is to change this value so it’s more accurate so if I Change that to 0.5 it does more checks which means more particles which means better chance of hitting inside the box anyways let’s pretty much it guys thanks for watching hopefully you found this useful I’m not gonna have a download in the description so just go ahead and Copy stuff I guess one last thing that I want that I will show you okay so I put this command in here it’s a kind of like rearrangement of a previous thing I cover it as try to check if you’re looking at something and basically it’s does everything we just Did but slightly less accurate and only one command so I pasted it in the description it’s really interesting but it basically does a selection within a cone of the player but with only one command by checking if you’re looking at the entity but limiting you to a certain Distance so if I do this it will start glowing him once I activate that yeah it’ll start glowing when I look at them so this is like a I don’t know how to use that effects kind of trick but it’s not perfect and you have to tinker with The conic selection but it’s pretty cool you can mess with I believe it’s this value here in conjunction with this value here to change how mainly the distance value here to change how wide the selection range is so I have it tuned here to be pretty tight but it’s Kind of interesting that it’s able to work anyways other that guys thanks for watching and I’ll see you next one peace Video Information
This video, titled ‘Raycasting Hitbox Tutorial in Minecraft’, was uploaded by Cloud Wolf on 2020-04-16 17:21:33. It has garnered 20380 views and 569 likes. The duration of the video is 00:14:55 or 895 seconds.
We cover how to make hitboxes for raycasting!
💡 Conic Selection: /execute as @p at @s anchored eyes as @e[distance=..6] facing entity @s eyes anchored feet positioned ^ ^ ^1 rotated as @p positioned ^ ^ ^-1 if entity @p[distance=..0.35] positioned ^ ^ ^1 run effect give @s glowing 1 0 true
⚔️ Server IP: cloudgames.ml 🔵 Discord Server: https://discord.gg/HyZPCTu 💻 Website: https://dtdeadpool.wixsite.com/cloudgames 🐺 Twitter: https://twitter.com/cloudwolfbane 📧 Email: [email protected]
Music: “Werq” Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 4.0 License
All Songs Used under fair copyright. Lincenses Below: License for commercial use: Creative Commons Attribution 4.0 Unported “Share Alike” (CC BY-SA 4.0) License. Full License HERE – https://creativecommons.org/licenses/by-sa/4.0/legalcode