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..
@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.
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.
@Sw_aG Get the Location using getLocation(), not getEyeLocation(), and then just don't change the world, x, y, and z.
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
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);
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.
@Sploon Have you even read what I wrote above ? That's exactly what I want, them both to look to the same direction
@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.
@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.
@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)
@Sw_aG I looked this issue up, and it seems there's quite a few issues like this one. It seems like the direction isn't updated until (maybe) someone pushes the entity. Try reading this: https://www.spigotmc.org/threads/direction-yaw-and-pitch-not-working.50972/ Otherwise, try looking up another thread on this issue.
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*