Copy Cat

Discussion in 'Plugin Development' started by Sw_aG, Jan 29, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Sw_aG

    Hello devs !
    I'm trying to make an entity look the same place a player is looking but no luck with it, any help ?

    What I have tried:
    PHP:
    horse.getEyeLocation().setX(p.getEyeLocation().getX());
    horse.getEyeLocation().setY(p.getEyeLocation().getY());
    horse.getEyeLocation().setZ(p.getEyeLocation().getZ());
    horse.getEyeLocation().setYaw(p.getEyeLocation().getYaw());
    horse.getEyeLocation().setDirection(p.getEyeLocation().getDirection());
    horse.getEyeLocation().setPitch(p.getEyeLocation().getPitch());
    Went over max, tried all of them, nothing worked..
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    KarimAKL

    @Sw_aG getLocation() & getEyeLocation() both return copies of their location, you need to get their location, modify it, and then teleport the entity, as @timtower said.
     
  4. Offline

    Strahan

    Won't teleport just place the entity where the player is looking? I thought from his description he just wanted them to look at the same thing the Player is.
     
  5. Offline

    Sw_aG

    Precisely !
    I don't want to change the entity's location.

    Edit: @KarimAKL OMG Duh ! the shame xD
     
    Last edited: Jan 30, 2020
  6. Offline

    Sw_aG

    Someone knows how to do it ?
     
  7. Offline

    KarimAKL

    @Sw_aG Get the Location using getLocation(), not getEyeLocation(), and then just don't change the world, x, y, and z. :p
     
  8. Offline

    Sw_aG

    Thanks for replying !
    Tried it, teleported the entity to a new location made from his own x y z but the player's pitch & yaw.
    Nothing happened :(
     
  9. Offline

    KarimAKL

    @Sw_aG Show us your current code.
     
  10. Offline

    Sw_aG

    PHP:
    Location loc = new Location(horse.getWorld(), horse.getLocation().getX(), horse.getLocation().getY(), horse.getLocation().getZ());
    loc.setYaw(player.getLocation().getYaw());
    loc.setPitch(player.getLocation().getPitch());
    horse.teleport(loc);
     
  11. Offline

    Sploon

    Pitch and yaw is the direction the entity is looking. So what the code above does is set the entity to look in the same direction as the player -- not in the direction of the player.
    If you want to get the direction from the entity to the player, subtract the player's location from the entities location. If you have the difference as a vector, you can pass this to Location's setDirection method.
     
  12. Offline

    Sw_aG

    @Sploon Have you even read what I wrote above ?
    That's exactly what I want, them both to look to the same direction
     
  13. Offline

    KarimAKL

    @Sw_aG
    1. You don't need to create a new location, you can just set 'loc' to horse.getLocation().
    2. Are you sure the code is run? Try debugging it.
     
  14. Offline

    Sw_aG

    @KarimAKL I did, I got the message from the debug.
     
  15. Offline

    Sw_aG

    *Bump*
    Does anyone has any lead ?
     
  16. Offline

    Sw_aG

    *Bump*
     
  17. Offline

    KarimAKL

    @Sw_aG Try teleporting the entity to another X, Y, and Z, (still with the player's yaw and pitch) then see what the result is.
     
  18. Offline

    Sw_aG

    Just did (again), nothing happens
    Also tried debugging it, went through
     
  19. Offline

    KarimAKL

    @Sw_aG Wait, so the X, Y and Z doesn't even get updated?
     
  20. Offline

    Sw_aG

    @KarimAKL They are, he's being teleported just fine but he's not looking anywhere
    I even cancelled his AI, but he doesn't change his eye location at all now (also tried it with his AI on, still, nothing)
     
  21. Offline

    KarimAKL

  22. Offline

    Sw_aG

    @KarimAKL Wow, thanks !
    I really appreciate the effort
    Will try this
     
  23. Offline

    Sw_aG

    Karim's suggestion wasn't it, I tried giving the entity a bit of velocity, he's just being pushed a little and he's not changing his eye location, so *Bump*
     
Thread Status:
Not open for further replies.

Share This Page