Vehicle Moving Distance

Discussion in 'Plugin Development' started by NinjaWAffles, Mar 19, 2012.

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

    NinjaWAffles

    Hey, So the plugin I am making consists of a section where I need to allow a player to get into a boat, and sail across the ocean, but when he gets out, the code will automatically figure out how many blocks he traveled in that period of time, and will log it. My struggle is getting the code for finding the distance of blocks he traveled.

    Please help me if you can!

    Thank~ :D
     
  2. Offline

    desht

    Well, if you know the starting and finishing locations (which you've presumably recorded in the VehicleEnterEvent/VehicleExitEvent handlers), it's just a matter of using Pythagoras's theorem in 3 dimensions:
    PHP:
    int distance Math.sqrtMath.pow(startX endX2) + Math.pow(startYendY2) + Math.pow(startZ endZ2) );
    Whether you use integer or double arithmetic is up to you, and how precise you need your answer to be.
     
  3. Offline

    fromgate

    VehicleEnterEvent/VehicleExitEvent handlers), it's just a matter of using Pythagoras's theorem in 3 dimensions:

    int distance = loc1.distance(loc2);
     
  4. Offline

    desht

    Doh, of course :p Totally forgot there was a Bukkit method for it.
     
Thread Status:
Not open for further replies.

Share This Page