Fear Effect

Started by BryAstro on

Topic category: Help with modding (Java Edition)

Last seen on 05:40, 20. May 2024
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Fear Effect
Sun, 11/26/2023 - 08:26 (edited)

Version 2023.3 (1.20.1 Forge) (yes i finally quit trying to make a 1.12.2 mod)

Hello, I would like to make a fear effect that makes any entity (including players) uncontrollably move to a random position. How do I make a simple procedure that makes the effect do it? Bonus points if you can also make the procedure affect the FOV.

Edited by BryAstro on Sun, 11/26/2023 - 08:26
Last seen on 11:41, 17. May 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
FOV is tricky, since it's…
Mon, 12/11/2023 - 12:32

FOV is tricky, since it's usually only effected by speed, but you might be able to do it with custom code. To do this for entities, you would probably just use the 'navigate to position' with random x/y/z offsets, though you'd also probably want to make sure they're navigating to a location the pathfinding can actually get to if you want them to actually go there. So I would say generate a random x and z offset as local variables, then check every block within eight blocks or so upwards or downwards to see if it's an air block with a solid block beneath it, and use that to determine the y offset. 

This has some drawbacks, (namely that, while the default pathfinding is stupid, it isn't stupid enough to go over edges or walk into danger, and it also won't go very fast), so you could also try using the override motion vector function to either add random velocity to the entity while it's on the ground, or add velocity from the entity's look angle vector, causing them to accelerate in the direction they're already going. You'd also likely want to add a cooldown between when pathfinding triggers, using another effect or an NBT number tag for a timer, otherwise the pathfinding will update constantly and the entity will just shake in place.

Making this work with the player will be much more difficult. You would have to exclusively use the override motion vector function, which isn't to say it's impossible: you could have some player persistent logic and number variables that correspond to the arrow keys and look-direction, then randomly change them and add velocity/change the player's look position based on the variables. (With different effects depending on how often you're going to update this.) Not exactly sure how you'd do this, particularly in terms of randomly changing where the player's looking, but it's not totally impossible.