Detect when entity collides with obstacle?

Discussion in 'Spigot Plugin Development' started by jakeob22, May 17, 2017.

  1. I'm attempting to have an entity do something when it can no longer reach the player it's chasing. For example, if the entity is chasing a player but the player places blocks in the way of the path. Is there a simple way to detect when the entity gets caught on something? The only way I can think of is loading all of the entities that are targeting players into an array, parsing through the array, and checking whether those entities have been stationary for a significant amount of time. To me, this seems pretty inefficient so I'm wondering if there's a better way to go about it. Thanks!
     
    #1 jakeob22, May 17, 2017
    Last edited: May 17, 2017
  2. Might not be much more efficient, but a move event - if the player's velocity is less than a certain amount, get the direction they're facing and check if there's a non-air block directly in front of them (there's a bit more to it but that's the core idea)
     
  3. Yeah, I was thinking about doing that. I'm mostly doing it just for Zombie entities and I couldn't find a move event for anything except for a player. If anything, that would be easier to code.
     
  4. Then maybe a scheduler? Just loop every second or however long then check the same factors above for each zombie you're tracking
     
  5. Yeah, that's what I was thinking of doing. Guess I'll give it a go and see how well I can make it work. lol
     
    • Creative Creative x 1