Change shooting accuracy on entities

Started by benl4b on

Topic category: Help with modding (Java Edition)

Last seen on 15:48, 22. Jul 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Change shooting accuracy on entities

Hey! 

I would like to add a sniper entity, who of course has very good accuracy, but at greater distances he only misses. 

I've already looked in the forum, there are others who have asked this, but the answers mostly didn't make much sense. Afterwards, I looked again at my entity's code, but didn't find a simple solution. 

Can someone help? 

Thx.

Last seen on 18:06, 24. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The problem you're running…
Sat, 10/28/2023 - 19:24

The problem you're running into is that entities have inaccuracy coded in by default, so they aren't totally overpowered. This is really apparent when you try to get an entity to shoot at something more than a dozen or so blocks away, it's almost comedicly bad at aiming.

One thing you could try is using procedures to shoot projectiles from the entity's location, with the entity as the owner. The tricky part is then doing the math to get the entity to actually aim at a location, which is made even more complicated by the fact that most projectiles are affected by gravity. Essentially, you'd have to do an arc-projectile calculation, which I only vaguely remember from AP Physics, and which I haven't been able to get working no matter how much I beat my head against it. 

You could try making your sharpshooter's projectiles unaffected by gravity, in which case you might be able to get away with forcing the entity to look at the nearest player, and then firing the projectile with its velocity set to the x/y/z look angle vectors of the sharp shooter. (You can then multiply each of the look angle vectors by the same amount to change the speed of the projectile.) I'm pretty sure this would work, but entity behavior is always weird to work with, so take it with a grain of salt.

Last seen on 15:48, 22. Jul 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think that's a bit too…
Sun, 11/05/2023 - 05:31

I think that's a bit too complicated for me... XD