Started by
Tucky143
on
Topic category: Help with modding (Java Edition)
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.
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.)
Can you give me the code or image of the procedure for it?
Something like this, for the simplest method: