Started by
SparkleArts
on
Topic category: Help with Minecraft modding (Java Edition)
Is it possible to detect from where you being attacked from?
Like the Damage Tilt Mod or the Attack Indicators where you see a red arrow from where you being attacked.
Yes, and I just figured it out by trial and error. The correct way to do this would involve trigonometry: you would need to calculate the angle of a vector from the attacker to the target, and then display the correct indicator based on the size of the angle. (This is made even more difficult by the fact that Minecraft's degree system goes from 0-180 and to -180, presumably to determine the direction of turns and stuff.)
Because I don't remember next to nothing about trigonometry, I just made a procedure that determines which of eight directions the player is looking at, (the cardinal directions and the diagonals), using their Yaw. (Which, again, switches to negative numbers once it goes past 180.) Then, depending on where they're looking, whether or not the x or z positions of the attacker are greater or less than the x and z positions of the target can tell me which direction to display the overlay.
For the cardinal directions, there needs to be a margin of error; otherwise it will only do the side indicators. Have the procedure check the cardinal directions first, and also check that the opposite value falls within a certain range. If the player is facing directly north, for example; and the attacker is in front, (their z value is greater than the player), also check that the x value of the attacker is within 0.3 blocks of the target. Otherwise, it will only ever display the left and right indicators even if the attacker is directly in front. If you check for the front and back first, you can then do the Left and Right indicators based on the other position value.
...It's not an elegant way to do it, but it works pretty consistently.
Can you show me a Procedure Image of that?
Have you already learned how to do this? Can you show me please?