[Solved] How to get an entity to move to another entity's position w/out attempting to path find?

Started by Memebassador on

Topic category: Help with modding (Java Edition)

Last seen on 21:12, 4. Sep 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Solved] How to get an entity to move to another entity's position w/out attempting to path find?
Tue, 07/23/2024 - 02:28 (edited)

Hi all,

So currently, I am trying to make bats hunt silverfish. I cannot use the pathfinding function to do this as bat's movements are too sporadic. So I figured, what if the bats instead do a homing attack every 5 seconds?

So: Get the position of the silverfish and the position of the bat and define a vector with these two points. This vector specifies the difference in x, y, and z coords between the two mobs. To get x, y, and z velocities out of this vector, we need a time to divide each coord by a time. In my case, I want the move to be made in 1 second, so the magnitude of the velocity for each coord is just equal to the direction for each coord. Makes sense, right?

Look at the code: https://imgur.com/a/mcreator-code-7-22-2024-7Y9E0om
 

Can anyone tell me why this doesn't work? The bats seem to have more velocity than I expect, and often move away from the silverfish rather than toward. Sometimes they even disappear (I think they are moving underground). I have tried to define the vector going from silverfish to bat (the code as shown is going from bat to silverfish), and that has not worked either.

Thank you.

Edit: This has now been solved, the code works but it wasn't working either because of updating my MCreator version or my Minecraft and Forge version while updating the mod. The fix was to delete and recreate the procedure as written. Not really an elegant solution since I am not sure how it broke in the first place, but oh well.

Edited by Memebassador on Tue, 07/23/2024 - 02:28
Last seen on 16:35, 6. Sep 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
https://imgur.com/rnPQYep …
Mon, 07/22/2024 - 13:28

https://imgur.com/rnPQYep 

Now bats always move to silverfishes position

Last seen on 21:12, 4. Sep 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am unsure how this is…
Mon, 07/22/2024 - 22:36

I am unsure how this is different from what I am currently doing, since you are doing batx - silverx and then doing 0 minus the result as opposed to my silverPosX - batPosX. In any case, I am seeing the same behavior I saw before. Are we using different versions or something? I am on MC 1.20.1, MCreator 2024.2

Last seen on 16:35, 6. Sep 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
looking at both procedures I…
Tue, 07/23/2024 - 00:25

looking at both procedures I noticed that they're literally the same too (I didn't check before because I assumed yours didn't work so I just made it different) now I did some tests and my procedure works for me, and yours works too, bats actually dash towards silverfish (MCreator version is the same), the velocity thing is normal, but if bats still go to the opposite direction I don't know how it's possible that they don't for me

Last seen on 21:12, 4. Sep 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Bruh. The only other thing I…
Tue, 07/23/2024 - 01:32

Bruh. The only other thing I can think of, are you testing within MCreator or in a separate Minecraft client? I have no idea why that would matter, maybe the Forge version is different and messing something up...

Last seen on 16:35, 6. Sep 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm testing within MCreator,…
Tue, 07/23/2024 - 01:39

I'm testing within MCreator, maybe you could put your workspace on google drive and send me the link to download it so I can check if it doesn't work using yours, or I could send you mine and you check if it works or not

Last seen on 21:12, 4. Sep 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No need. I made a new…
Tue, 07/23/2024 - 02:03

No need. I made a new workspace and only included the procedure for my code. Annoyingly, it now works... so now I have to just add all of the features of the mod I was working on to a new workspace. It seems updating the game version is what caused the issue. Maybe debugging the client can fix it...

Last seen on 16:35, 6. Sep 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That's really weird, but at…
Tue, 07/23/2024 - 11:10

That's really weird, but at least you have some kind of solution now