Hey guys welcome back and today I have something truly amazing to show you Ray casting in one command block so I know before I did a little mini-series on game or Guppies ray casting system but now I have my own ray casting system for 1.13 and I know it may seem a little Redundant to be like oh dude they already have ray casting it already exists it’s uh it’s you you the upper upper upper one yeah that makes sense but I’m talking about like Ray casting like in a game I’m talking about ray casting like where when I click some When I shoot right it traces a line exactly where I’m aiming all the way to a ball like so it traces the line all the way to a wall until it finds a wall or it finds an entity like oh well that counts as a wall like so it stopped at The Sheep now if you notice that my chat it might be hard to see exactly but when I right click let’s look straight up when I click it says 539 commands executed I set it to one command because it really is one command it’s just doing It 530 90 three times and these two commands are a part of the Ray casting itself as a part of detecting when the player wants to do it so I don’t technically count it but yeah so here we have it that’s that’s it it goes it traces a line straight forward until it Reaches a wall now it’s really dumb using the barrier and I have some limitations so it doesn’t do it as much but as you can see like see it did a straight line all the way there but using the barrier particle looks a little strange so just keep that in mind And you can increase the accuracy if you want but yeah so there we go yeah the barrier particle has strange behavior but this really does extend until it hits the ground so now let’s look at exactly what’s going on this is the function that I use and as you can See it’s really simple right so here we have one command that I’m not gonna count it’s call it plays the particle this is just so I can see it you don’t have to have the particle in the command you don’t have to have the particle at all it works without the particle it’s Just there so like you can see that it’s working this is the only command just one of them now I know it seems like really big but it’s the only one so I did it done no explanation I’m just kidding I’ll show you so what we’re doing here is we’re Playing this function of one time using this command block here this is going to play the function if I right-click a carrot on a stick that’s what the score shoot is for it tests if you right-click the carrot on a stick this is gonna play the function if I right-click a carrot On a stick now I have this additional things so that it shoots out of my head you could I’ve changed some of these values for my zombies game that I’m working on so that it shoots out of the tip the gun but you can rotate where the Function is what the function is being played you can rotate the position in the line move it so that it looks differently if I don’t have these positioning commands in here what it’ll do is it’ll shoot it right out of my feet which is not really what I want so Anyway it is that and then this just sets my score back to zero so these two are just for detecting when I right-click of course what I use for my zombies is I test it when a player right clicks then it takes them to a function file not this one a different function File that checks what gun they’re holding and then it takes them once it finds the gun they’re holding into another file and it’s it detects well it’s like an initialization function and the function basically just plays just does this command to start the function it can play just this command say just This one time so I’ll right click I’m playing the function I’m using one command to play the function one time and then it repeats the itself over and over and over what’s going on is it’s kind of doing like a recursive thing and the reason why you don’t see it moving Forward the reason why it’s so nice is because functions stop your game to do the calculations and then play your game again I believe that’s how they work so all of this if I right-click it’ll pause my game freeze everything I can’t see anything run the function until it’s done running Which is an infinite loop until it reaches a wall or or or until it reaches a wall a location that doesn’t have air which would be a chunk that’s not loaded or it reaches an entity so once it finds one of those conditions it plays my game Again and it’s able to do it really fast because it’s not too many things happening so yeah that’s that’s the raycasting in one command now let’s go over with the axe function does so you play the function and in the function it executes so it’s going to play the function again if the Block that the function is being played at is there and if an entity if it didn’t hit an entity this positioning stuff is just so that I can grab get really accurate entity tracking I have to change the positioning of the command so that it tracks a little better for Entity since the entity’s origin hitboxes towards their feet and then it moves the commit it moves the function to be played one block forward in the direction that the function is looking and then moves it back up so these two cancel each other out so you can ignore Those but basically it’s saying if the block is there and unless unless there’s an entity there so if there’s not meant to be better than it’s fine but unless there’s an entity there then does it move the command forward one block in the direction that the command is facing And play the command again that’s about it play the function again so it just does that over and over so it gets played right here checks is it air is there entity no then we will move forward one block and do it again and move forward a block and do it again and We’ll forward a block and do it again and before the block until it stops and it’s really that simple now you know the positioning thing is annoying but one of the coolest parts about this is check this out say at s hit a wall check That this out so now you may be thinking okay is it selects the entity that that is basically not like it picks the entity that’s playing with this command but since we never change what entity is playing this command it’ll still pick it’ll still pick me oh I have to do Reload it’ll still pick me so it’ll say cloud wolf okay I shouldn’t have put it in that sense because then it plays it every time but you know class it says my name it says my name here as you can see and the reason why it says my name is Because I didn’t change what entity is playing the command so I can do stuff like I can set up a damaged system and have some kind of reward in the system I could make it so if I’m doing a quake style game I could go like that right And then when it hits right so you execute app this entity so let’s go execute if there’s an entity there it’s executing if there’s an entity there it’s gonna play another function and that function we can use to kill that entity so kill say another player and Tell the whole world that at s which is me kill that player so I think that’s really cool that you’re able to also keep track of who’s who like who shot it and I this is a definitely a really really powerful thing it’s literally everything you could ever ask for with Raycasting and gun shooting and anything and only one command so hopefully you guys are able to use it for something cool I have it in if you guys have not seen it yet I have used it to a great extent in this other example I posted a Video on this a couple days ago so my pre video right before this but you know I use it to a great extent in this where as you can see there’s the little the little tiny dots that’s our representation of the bullets trail and you know we have zombies so here the Zombie falls and if I shoot it it kills the zombie and if I scoreboard objectives that’s this place sidebar or wow this is train wreck scoreboard addictive let’s play sidebar is on the score there we go if you see on the sidebar it says my points is 80 right so If I go back into here and have the zombie spawn again if I shoot them you’ll see I suck you’ll see my points go up every time I hit them and that’s because I’m using the whole thing where the function knows who shot it regardless of how far away it’s being Played now another cool thing you can do is with the same function you can use it to create accurate looking little blood particle effects so if you notice the blood that I shoot at their legs the if I shoot at their legs the blood comes Out of their legs just like it’s hard to do while running backwards but if I shoot at their head blood comes out of their head especially at their body out of their body and so on and so on so you can get a lot of accurate looking things From just you know pretty much one command like the majority of what’s happening runs off of the fact that that one command does the rate casting for you which is pretty great and it pauses your game to do so and I’m getting low frames and it’s probably just because I’m recording but anyways guys that’s all I wanted to show you today a really simple way to do Ray casting with only one command in a function file and probably one or two other commands to to make it activate but essentially one command in a function file gives you a Casting and hopefully you guys thought that was interesting or useful and I wish you the best of luck working with this it’s a really cool thing I love 1.13 it’s got a lot of great features if you guys want to see anything else just let me know and I’ll be coming out with New videos soon on some other cool things so stay tuned for that subscribe if you haven’t already anyways guys thanks for watching and I’ll see you in the next one peace Video Information
This video, titled ‘Raycasting in Minecraft (1 Command)’, was uploaded by Cloud Wolf on 2018-05-10 18:15:08. It has garnered 48172 views and 911 likes. The duration of the video is 00:10:08 or 608 seconds.
We go over a way to do perfect raycasting with only 1 command!
The Basic Command: execute if block ~ ~ ~ air positioned ^ ^ ^1 run function test:raycast
This should be put in a function file named raycast in a datapack named test. You can obviously change test to whatever your pack is called and raycast to whatever your file is called. This version only stops when it hits a block, but as shown you can add things to make it stop for entities.
🙏 Donations: https://www.patreon.com/cloudwolf 💻 Website: https://dtdeadpool.wixsite.com/cloudwolf 🔥 Lit Discord Server: https://discord.gg/HyZPCTu 🐺 Twitter: https://twitter.com/cloudwolfbane 📧 Email: [email protected]