# Direction between two locations.

Discussion in 'Plugin Development' started by evyatar, Apr 11, 2014.

Not open for further replies.
1. Offline

### evyatar

I have got a problem while making my plugin...

I want get the direction between two locations like in a compass but it's not working for me...

Code:java
`LivingEntity mostnearby = null;         for (Entity le : p.getNearbyEntities(20, 20, 20))            if (le instanceof LivingEntity) {                LivingEntity target = (LivingEntity) le;                 if (target.getLocation().getY() > p.getLocation().getY())                    continue;                  if (mostnearby == null) {                    mostnearby = target;                    continue;                }                 if (mostnearby.getLocation().distance(p.getLocation()) > target.getLocation().distance(p.getLocation()))                    mostnearby = target;                else                    continue;            }         if (mostnearby == null)            return;          Location pLoc = p.getLocation();        pLoc.setX(p.getLocation().getBlockX());        pLoc.setY(p.getLocation().getBlockY());        pLoc.setZ(p.getLocation().getBlockZ());        pLoc.setPitch(0);        pLoc.setYaw(p.getLocation().getYaw());         Location tLoc = new Location(mostnearby.getWorld(), mostnearby.getLocation().getBlockX(), mostnearby.getLocation().getBlockY(),                mostnearby.getLocation().getBlockZ());        tLoc.setPitch(0);        tLoc.setYaw(0);         float yaw = (float) (tLoc.toVector().angle(pLoc.toVector()) * Math.PI  * 6300) ;`

Thanks for any help

#1
2. Offline

### Zethariel

You mean the vector between two points? That's geometry. Substract coordinates of the beginning point from the end point - you'll receive a fector facing towards the end point.

#2