Force Push

Started by Tucky143 on

Topic category: Help with modding (Java Edition)

Last seen on 18:14, 28. Apr 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Force Push

I was trying to create force push keybind procedure but it wouldn't work. Can someone tell me what I would need to do? I want it to where if there is an entity in the direction your facing when the key is pressed, it will push that entity in the direction you are facing. Same, but opposite for force push.

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There's a couple ways to do…
Sun, 04/07/2024 - 17:44

There's a couple ways to do this. The tricky part is mostly just choosing which entity to target.

The easiest method would be to use an entity iterator bracket to target all entities within a certain radius. (Code that targets the 'entity iterator' will be run on every entity in the radius.) You would want to check that the entity iterator does not equal the event/target entity, (otherwise the force push will also push you), and then use the 'attempt to override motion vector' function to set the x/y/z velocity of the entity iterator to the x/y/z look angle vectors of the event/target entity. This will cause all nearby entities to immedieately lose all velocity, and then move at a constant rate in the direction the player is looking while within the provided radius. (You can then multiply the look angle vectors to increase the strength of the push.) If you add the look angle vectors to the entity iterator's current x/y/z velocities instead of just overriding them, the force push will gradually override the existing motion of the nearby entities.

To target a specific entity, you would still need to use an entity iterator, but would also probably need to check if the entity iterator falls within the player's field of view. (That is, depending on the direction the player's looking, you would want to check if the entity iterator's position indicates it's in front of the event/target entity.) 

Last seen on 18:14, 28. Apr 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you give me the code or…
Mon, 04/08/2024 - 23:43

Can you give me the code or image of the procedure for it?

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Something like this, for the…
Tue, 04/09/2024 - 17:04

Something like this, for the simplest method: