[Tutorial] How to use the Direction and Head pitch procedure blocks

Started by mega1134227 on Fri, 09/03/2021 - 02:56

Topic category: User side tutorials

Last seen on 02:56, 24. Oct 2021
Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[Tutorial] How to use the Direction and Head pitch procedure blocks
Fri, 10/22/2021 - 12:18 (edited)

First of all, I would like to mention that this tutorial covers a mathematical subject that isn’t exactly difficult to wrap ones head around (on the basic level), but isn’t known by everyone already. What’s more, even though you might know how PI π Radians work, I’ll still be showing you something you might not have known you could do.
Even if you don’t know what π Radians are, you’re going to get through the tutorial fine. People who understand this will be able to push the concept farther though.

To start crafting, you will need 4 math procedure blocks. Find your division math block, your pi math block, your cos and your sin math blocks. These can be found by transforming the random block and the round block into their variants.

We will also need our procedure blocks :

  • direction (yaw) of entity
  • head pitch in degrees

Notice how head pitch is in degrees. Even though it’s not mentioned, yaw is also in degrees. The reason why these blocks act weirdly is because when you use them like this, they aren’t working in the way mob rotations were calculated.
Mob rotations work in Radians. Circles are normally 360 degrees, but in radians they’re 2π. So we have to transform these values.

Step one :
Although recommended to optimize and code this easier, it’s not necessary.
Make 4 new local number variables in the procedure called PITCH, PITCH2, YAW and YAW2.

  1. PITCH = cos[ HeadPitch / (-180/π) ]
  2. PITCH2 = sin[ HeadPitch / (-180/π) ]
  3. YAW = sin[ Yaw / (-180/π) ]
  4. YAW2 = cos[ Yaw / (-180/π) ]

We do this to transform our 360 into 2π.
360/-180 = -2
(dunno why it has to be -2 with minecraft. Normally it isn’t, but it works here)
Then,
360/(-180/
π) = π * 360/-180 = -2π

You can use these to do many things with your camera, like draw particles EXACTLY where you’re looking or move a creature where you’re looking using vectors or to move things towards you using vectors again.

Step 2 :
This is the weird part to understand. To draw particles where you’re looking, you have to first get your single or multi-particle generator procedure block. It has to be the one where you spawn a single particle at an xyz coord and with a specific xyz speed.

Make the positions equal to :

  • x : x position of entity + (n * YAW * PITCH)
  • y : y position of entity + (n * PITCH2)
  • z : z position of entity + (n * YAW2 * PITCH)

n here is a random number of your choice. I recommend 1, but you can really use anything. It determines the distance in blocks your particle will generate at.
Entity positions are found at the bottom of Entity Management.
The rest are our custom variables.

The reason you have to use our variables this way is because we’re using two degrees to identify a 3-dimensional degree. The weird part being this thing. Ask yourself how could someone come to this conclusion when trying to put a dot in sphere using two perpendicular degrees and a random distance. You basically have to compress or multiply together the two circles defined by the degrees to make this sphere which is weird. Any other combination makes random things like non-sensical cones or semi-spheres or hyper-cylinders. Anyway, this is just me pointlessly ranting because I spent over 10 hours testing options and doing difficult math to reach the conclusion that this wasn’t exactly some godly formula I was looking for. Just... this thing.

After this, you plug in 0 in your speed vectors and trigger this procedure when you’re holding an item and you can start drawing! 

(Mind you, putting 0 in the single particle generator won't work because, at least from I'm gathering, the speed vectors are the position the particles are trying to reach. Put in the same YAW*PITCH blocks in the speed vectors to get the particle to float. I might be wrong though...)

You gotta remember though that putting these YAW2*PITCH things in your respective movement vectors can produce interesting movement and allow you to control creatures by looking in a direction.

Good luck and have fun!

Edited by mega1134227 on Fri, 10/22/2021 - 12:18