9/20/2023 0 Comments Minecraft block shooterAnd because X - 0 = X, we don't need to do the math ourselves but can directly store the result into the entity. Or rather, make use of the fact that we can use the worlds zero position and pretend the player is there. Method 1: Let the game do the math for us by using the zero point (optimised) Then we have V and can store it into the Motion values of our entity. From here vector calculations tell us that to get the movement vector V between those two points, all we need to do is T - P = V for each value individually (T.x - P.x = V.x etc.). So, we can get the players location using its Pos NBT values and we can summon an entity ^ ^ ^1 blocks in front of the player, using its Pos attribute to get the second position and thus we know starting position P and target position T. For the following examples we'll assume the entity should be shot out with a speed of 1 block per tick in the direction the player is facing ( ^ ^ ^1), but this can be altered to your liking (but remember the limit of 10 in the motion tag!). Luckily, we can get both of these positions from the local coordinates ( ^ ^ ^) of the shooting player. To find the correct Motion to apply, we need to find the difference between the position the entity starts in and the position the entity should be in the next tick after that (because that's how far it's supposed to move in this one tick). Motion will also automatically be changed by the games physics engine, so we only need to set the initial motion and the rest will happen by itself. A value of 1 means a motion of 1 block per tick in that axis positive direction. Each value is limited to and will be clamped to these values if you go above or below this limit. Motion is a three dimensional vector, where each axis corresponds to one of the ingame directions: Motion. The end goal is to find the correct Motion values to apply to the entity for it to fly into the correct direction. Sounds complicated, but is actually pretty easy. Related: How to detect item click Using teleports to essentially do vector calculations Explanation If you're using an older version that doesn't have the marker entity yet, swap it out for an area_effect_cloud. This article has been updated to use a marker entity. That technique however is completely obsolete as of 1.13. Shooting a projectile/entity in the direction a player is facing is not trivial, and in the older versions of the game, the process was to basically hardcode a bunch of possible motions for various facing values of the player. It is highly recommended that you use functions for this and already know how execute at and execute as works! This doesn't work in bedrock and there are currently no known workarounds.Īdvanced. Shoot a Projectile/Entity in the direction a player is facing Method 2: Storing all values (for easier manipulation).Method 1: Let the game do the math for us by using the zero point (optimised).Using teleports to essentially do vector calculations.Shoot a Projectile/Entity in the direction a player is facing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |