Monitoring a Entity Along Vector through Coordinates

Discussion in 'Spigot Plugin Development' started by WAS, Apr 20, 2017.

  1. WAS

    WAS

    Does anyone know a good method that one could use to track a entity along it's vector and when it enters a new block coordinates do something? I can't even think of how that would be done so I'm not exactly positive it can be.
     
    #1 WAS, Apr 20, 2017
    Last edited: Apr 20, 2017
  2. You can have a scheduled task getting the location of an entity every so often and comparing it to its previous location. I wouldn't recommend tracking it on a vector as entities can change directions and be off that vector.

    If your scheduled task ran every 10 ticks that would be checking every half second roughly.

    If the distance from its last point was > 1 it would have moved a full block. Then update the previous location with the new location and continue tracking it if need be. Or never update the previous location from the initial setting and once the distance is 20 blocks or so do something.

    Entities are pretty easily tracked like this and you've got the power to speed them up, slow them down, remove them etc

    Edit if you're going to be possibly tracking a lot of entities at once I would advise making a single task that stays running and add/remove the entities as they need to be tracked over creating a separate task for each entity.

    Sent from my iPhone using Tapatalk
     
  3. WAS

    WAS

    It's a custom flying entity, with a set vector. It doesn't deviate form this unless colliding which would be the end-of-route. I wanted to do this without tasks running if at all possible.
     
  4. Still tracking the entity and getting its location every tick or 5 ticks would be far easier than getting every location along a vector imo.

    I mean I suppose you could calculate every Integer xyz between two points and measure that but it seems unnecessarily complicated when you'll have the start point and can measure distance easily using ent.getLocation().distance(otherLocation)


    Sent from my iPhone using Tapatalk