Engine for EntityPlayer Movement

Discussion in 'Spigot Plugin Development' started by Simagdo, May 19, 2018.

  1. Hey there,

    I am currently working on an engine for an EntityPlayer which allows the to move from Position A to Position B. I am currently doing this with multiple Vectors but the Problem is, the Player can go through Blocks, because im adding a specific value from the calculated Vector to the current EntityPlayer Location. My question is now, how could i create a better Engine which allows me that the Player Jumps on the Block in front of him or goes right or left based on where he should go.
    If you have any Ideas, how i could achieve this, would be awesome. I could create a Vector for each Step they walk but i think this wouldn't look really good.

  2. Because Minecraft already implements path finding, it could be possible to use NMS code for finding the path and then using this path with your current movement system.

    Or if you have other requirements or probably just want to learn about path finding and how Minecraft does it:
    You could take a look at some path finding algorithms, an example algorithm used for this would be the A* search algorithm or Dijkstra's algorithm. You'll have to change a bit because these are usually for 2D environments and Minecraft is 3D and has jumping so you can get down as much blocks as you want (if you don't care about fall damage) but can always only jump up 1 block and you need to make sure that not only one block is free to determine if the player can walk there but also consider the 2 blocks heigh bounding box, then there special exceptions with passable blocks for example plants and sometimes passable blocks like doors or fence gates which can be opened or closed.
    If you do not have any experience with these algorithms, I'd suggest you learn about them, there are probably also a lot of Youtube videos on them, try programming them in a simple 2D environment and then move up to 3D and later on also try to take care of the special cases I mentioned.

    And I just remembered that there is an actual implementation for path finding in Minecraft (outside of NMS code of course), Darkstorm652 made a pretty advanced Minecraft bot which uses A* to walk around, follow players etc: https://github.com/DarkStorm652/Dar...kstorm/darkbot/minecraftbot/world/pathfinding
    • Like Like x 1
  3. I think i look at the A* Search algorithm and try to implement it. I don't know, if it is worth it now because i have the main Engine done for now or if i recreate the engine after I have released the first version of my plugin.
  4. You likely don’t have to create your own engine because there are many open source libraries out there that already do this. Citizens for example is a great open source plugin that uses the A* pathfinding algorithm for entity movement. You can look at the source here, and more specifically here look at the source for the A* pathfinding.
    Although, I would not suggest ripping the code out of their repo and trying to fit it into yours, but rather, simply use their plugin as an API for seamless and easy integration.