does anyone know how to make a weapon which pulls in enemies?

Started by Flarix on

Topic category: Help with modding (Java Edition)

Last seen on 18:51, 9. Jul 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
does anyone know how to make a weapon which pulls in enemies?
Sat, 11/11/2023 - 20:12 (edited)

i dont care how its done, be it code, blocks, or procedures. just wanna make it so that hitting a mob or player will make it kinda magnetically float to the attacker.

Edited by Flarix on Sat, 11/11/2023 - 20:12
Last seen on 16:12, 15. Oct 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The bad news is you're going…
Sat, 11/11/2023 - 17:04

The bad news is you're going to need to use a fair bit of trigonometry to do something like this. The good news is I've wound up doing this before, and have a decent example for how to do so: (Code] Trying to make block with bounce on all sides of block. | MCreator

Essentially, you'll want to make something using the example code. With some magical trig properties, it gets the line from the player to the target entity as an x/z vector, then uses that vector multiplied by your desired value to launch the entity. 

In your case, if you want this to only target a single entity instead of all nearby entities, you would want to remove the entity iterator block, and probably replace 'entity iterator' with whatever you're trying to target. (Which might mean swapping out 'event/target entity' and 'entity iterator' for 'source entity' and 'event/target entity,' depending on how you're triggering the procedure.) You will then probably want to multiply the end results by a larger number. (This procedure is designed to run every tick, meaning it increases velocity by a small amount very quickly.)

Lastly, you'll just want to multiply all the velocities by -1. The example I gave launches entities away from a position; simply inverting the end result will launch them towards a central position instead.