Get direction from location to location?

Discussion in 'Plugin Development' started by FurmigaHumana, Sep 4, 2012.

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

    FurmigaHumana

    Hi,

    I'm trying to figure out how to get the direction between two locations.

    Here is a image:
    [​IMG]
    /*I'm the paint master, and dunno how to make a compass.*\

    Ok, so, I know how to get the direction which the location 1 and 2 are pointing at.

    But now I need get the direction between those two locations [the pink line], I'm starting to think than that is not possible with the bukkit api...

    any ideias?

    thanks..
     
  2. Offline

    stelar7

    I think it should be possible with vectors
     
  3. Offline

    FurmigaHumana

    Maybe, but how?
     
  4. Offline

    stelar7

    psuedo-code:

    Code:
    Vector blockvector1 = block.getLocation().toVector();
    Vector blockvector2 = block1.getLocation().toVector();
    float angle = blockvector1.angle(blockvector2);
     
    Location loc = block.getLocation().setYaw(angle);
    player.teleport(loc);
    player.getLocation.setYaw(angle);
    
    if I'm right, the player should be teleported to point1, and look directly at point2
     
  5. Offline

    FurmigaHumana

    I guess it works, but not how I expected...

    This was supposed to work like a forcefield detector, but it seems the player really turn to the direction of the entity before attacking it D:

    Must have a way, I just don't figure it out yet...
     
  6. Offline

    ase34

    Do you mean the angle of the pink line relative to north? If yes, then it can be surely done with mathematics (that thing with the triangles)
     
Thread Status:
Not open for further replies.

Share This Page