Distance between cords, angle between it etc. How can i get this?

Started by Darknessay on

Topic category: Help with modding (Java Edition)

Last seen on 23:12, 10. Jan 2024
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Distance between cords, angle between it etc. How can i get this?
Mon, 12/11/2023 - 06:29 (edited)

Y know if i want to make some cool and vibe looking things like mobs from "mutant creatures"(mutant zombie's player throw + punch in air, for example), i need to know how to get directions, distances etc.

I know the squareroot and atan formulas, but i dont understand how to figure it with procedure blocks.
Can somebody give me some screenshots of getting it?

And also In minecraft there are exist things like "vector" and "yaw" - and i cant even imagine how these things are working and how to use it with atan and squareroot.
Can somebody give me some screenshots of using it?

I'm really dumb in math and all my understanding of these functions is based on my Warcraft III codding expirience, where i was only using stuff like this:
SetX = X+100*Cos(atan)
SetY = Y+100*Sin(atan)
or SetX = X+100*Cos(angle*0,0174) - if i use unit's face angle in degrees.
I dont even know what these "cos" and "sin" means. And in Warcraft 3 there was only two dimensions (Y - isnt Height), and if i had to make unit "jump", i used parabola or managed height by manual calculatings.
As you understand, things looks a bit harder for me with including third dimension, so plese, somebody, make my dumb head to find out how to make even a simple movement procedure like Huskar's ulti from Dota 2, be like:
1. Entity sets it's attack target.
2. If attack target isnt no entity, move targetting entity to targets direction each tick.
3. If distance between attacker and target equal or less than N make attacker stop his moving.
Y i know i have to use NBT values to switch phases of entity's action, i only want to know how to get distance and direction, and how to use it with set location and with override motion vector, and also with things like yaw and vector.
And if i want to make player dash in his look angle(i mean: without loc B for atan calculating. Just moving forward constantly, using a formula of direction calculating from players XYZ to player's look XYZ, not just override to it's look angle XYZ - ofc if its even possible or have a sense) how can i also use these "look angle vector"?

Sry for my bad english.
I believe there is people with advance in these things. Help me, please!

Edited by Darknessay on Mon, 12/11/2023 - 06:29
Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here's a related example of…
Mon, 12/11/2023 - 12:10

Here's a related example of something similar. May or may not be helpful: 

(Code] Trying to make block with bounce on all sides of block. | MCreator

 

The idea is sort of similar to your Warhammer coding. To the best of my understanding, the game calculates direction using three circles centered on the player; the x, y, and z look angle vectors; with x and z both being circles in the horizontal plane centered on the player, and y being a circle in the vertical plane centered on the player. Each circle ranges from a value of 1 to a value of -1. For example:

  • With the Y look angle vector, 1 is looking directly up, -1 is looking directly down, 0 is looking straight horizontally. If the Y Look angle vector is greater than 0, the player is looking with an upwards angle, and if it's less than 0, the player is looking with a downwards angle.
  • For the X look angle vector, 1 is looking east, -1 is west, and 0 is north or south. The Z look angle vector is similar, but 1 is south, -1 is north, and 0 is east or west. 
  • You can use the look angle vectors to move the player. All three vectors describe the direction the player is facing, though in most cases, (since you do not want the player to fly), you only need to worry about the X and Z components. The X and Z look angle vectors describe straight lines in the X and Z plane that, when combined, form a triangle whose third side is the direction you want to move the player. You don't always need to worry about the math, however; in most cases you can just add the x and z components to the player's x and z velocities separately, and the result will be identical.
  • To move the player in the direction they're facing, you can simply use the 'Attempt to override motion vector' block, and plug in the player's look angle vectors. (Ignoring y if you don't want them to be able to fly upwards. You could also add a check that only includes y if it's less than zero, and therefore downwards.) You can multiply the look angle vectors by any number or decimal to increase or decrease the force of the push; and you could also add the result to the player's existing velocities if you want them to accelerate, or if you don't want the change in momentum to be instant.

But yeah, with a few weird exceptions, you can use look angle vectors to get the individual components of the direction the player is looking at, and use them to get velocity. Trigonometry can be helpful, but is only necessary if you want to do weirder stuff. (Such as moving the player in different directions relative to their look direction, or relative to another point.)
 

Last seen on 23:12, 10. Jan 2024
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you for your answers…
Mon, 12/11/2023 - 13:59

Thank you for your answers to my topics and for this detailed answer in particular.
There is an excellent example in the topic you sent.

I didn’t understand everything that was written and I still have a mess in my head with all these “vectors”, “velocities” and other things.
I understand the meaning of these words, I understand how it works in Minecraft, but I don’t understand what kind of mathematics allows you to combine one with the other.
For example: I don’t understand why you need to multiply by -1 if the coordinates of the target and the caster are greater or less, if the atan itself should give the correct direction?

But don’t rush to waste your time on another detailed answer.
In the near future, I will try to repeat what you made, and then make something of my own based on it, and I will contact you here if I have any additional questions.

Thank you very much!

Last seen on 23:12, 10. Jan 2024
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mindthemoods, bro i really…
Thu, 12/21/2023 - 03:20

Mindthemoods, bro i really dont getting how to figure the procedure. Can you please give me a screenshot of exact procedure blocks with atan and square root calculating?