Help with moving entity to look position

Started by Kvngsavage118 on

Topic category: Help with modding (Java Edition)

Last seen on 04:09, 24. Jun 2024
Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help with moving entity to look position

I am making a mod that uses a living entity for an attack, and I made a keybind procedure that when I hold the button, said entity spawns and looks around, and when I release the button, it attacks.  The entity moves around, but not in the exact position of my mouse (around 1-2 blocks away from my mouse).  I've done the Look X,Y,Z raytrace procedure blocks but that hasn't been working for me.  Any help would be appreciated.

Last seen on 14:57, 22. Jun 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the raytrace blocks aren…
Thu, 01/25/2024 - 13:23

If the raytrace blocks aren't working, and, (if I understand correctly), you want the entity to teleport in the direction the player is looking at, you could try setting its position to the player's x/y/z, plus the player's x/y/z look angle vectors. (Which range from -1 to 1, based on the direction the player is looking at.) You can then multiply the vectors by a decimal number, (if you want the entity to be closer than one block), or by a whole number, (if you want it to be further than one block.) Since look angle vectors are always out of one, whatever you multiply will be the exact distance from the player the entity teleports.

Last seen on 04:09, 24. Jun 2024
Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Im trying to basically aim…
Thu, 01/25/2024 - 20:27

Im trying to basically aim an entity like an arrow.  So I want the entity directly in front of me where I look.

Last seen on 14:57, 22. Jun 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh, okay, that's actually a…
Fri, 01/26/2024 - 23:32

Oh, okay, that's actually a pretty cool idea! You want to sort of have it hover in front of you until you fire it? You would need to do something like this:

  • On your entity's tick, have it check if a player exists within a 5 or 6 block radius, and then check if the nearest player is sneaking. If both are true, set the position of the projectile to the x/y/z position of the nearest player, plus the x/y/z look angle vector of the nearest player, and disable gravity for the projectile. (This should make your entity hover just in front of the player, and follow the direction they're looking. You could also offset it downwards a bit so it's not directly in the player's view, or multiply the look angle vectors so it's a little further out from the player.) 
  • If at any time the nearest player isn't sneaking, enable gravity for the projectile, and set its x/y/z velocities, (using the override movement delta function) to the x/y/z look angle of the nearest player, multiplying each by however much force you want the entity to fly with.
  • You'd also probably want to make an edge case that despawns the entity if there is no longer a player nearby. (Say, if the player dies or teleports while wielding your projectile.) 
  • ...And of course this is for sneaking, but if you wanted to use a custom keybind, you would just need to make a custom player-lifetime logic variable, (I'll call it 'preparing,') then have your keybind set this variable to true whenever the player presses the key, and false whenever they release it.
Last seen on 04:09, 24. Jun 2024
Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much for…
Tue, 01/30/2024 - 03:30

Thank you so much for helping me!  I've been trying to figure this out for a while before you came along.