Solved Get directions(In blocks) from location 1 to location 2

Discussion in 'Plugin Development' started by Lightspeed, Apr 12, 2016.

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

    Lightspeed

    What I mean by is blocks is lets say we have:
    The 2 locations are the "()."
    ()[][] Location 1 + x, z
    [][][]
    [][]() Location 2 - x, z

    What I need is to get how many blocks I have to go to get from loc 1 to loc 2(-2, 0, -2).
    I'm REALLY bad at figuring out math problems to do somthing.

    Any ideas/pages for me to read/javadocs/anything?
     
  2. Mathematics.

    Basically, you can work it out by looking at the coordinates. It is 2 blocks x and 2 blocks y, 4 blocks.
    I'm not great at math either, but I think this works...
     
  3. Offline

    Lightspeed

    ?? Wouldn't this not work at different coordinates?
    Lets say Location 2 is at 179 how would I get the "directions" from either Loc1 to Loc2 and reverse?
     
  4. Offline

    ChipDev

    Do you want the LENGTH between the blocks? or the directions? :)
     
  5. Offline

    Lightspeed

    @ChipDev Well directions being how to get there from current coords.
     
  6. Offline

    Abstract97

  7. Offline

    Lightspeed

  8. Offline

    Abstract97

    @Lightspeed

    Do you want to get the amount of blocks or the actual block objects in-between those locations? Or am I totally missing the point?
     
  9. Offline

    Lightspeed

    I need to get the distance for all x y and z.
     
  10. Offline

    mythbusterma

    @Lightspeed

    Then subtract the x of one from the other, the y one of one from the other, and the z of one from the other...
     
  11. Offline

    Lightspeed

    That doesn't work with what I need. . .

    *Ok I need a bit more explaining I should of done in the beginning*
    I need to get the "distance" to get from pos1 to pos2 meaning I also need negatives to handle if your above pos1.

    I'm also bad at explaining if you can't tell. :I
     
  12. Offline

    mythbusterma

    @Lightspeed

    There's the Vector.distance(...) method. Also, absolute value is a thing.
     
  13. Offline

    Lightspeed

    I need to be able to get negatives not just plain distance.

    ()[][] pos1
    [][][]
    [][]() pos2
    I would want to be able to get -2, -2 from checking how to get to pos2 from pos1 and 2, 2 from checking how to get to pos1 from pos1.

    Does everyone understand now?

    *I thought abs removes the negative values?*
     
  14. Offline

    mythbusterma

    @Lightspeed
     
  15. Offline

    Lightspeed

    @mythbusterma That doesn't work if my position is higher than the other(Reverse positions). I already tried this.

    I also need to get pos 1 from pos 2 I can't just subtract higher by lower(Or the other way around).

    I'm basically getting the offset of pos1(Block) from pos2(Player).
     
  16. Offline

    mcdorli

    Loc1: 0, 0, 0
    Loc2: 2, 0, 2

    x1- x2 = 0-2 = -2
    z1-z2 = 0-2 = -2
    y = 0

    This is what happens if you use mythbusterma's algorithm for the direction between loc 2 abd loc1, it works perfectly.
     
  17. Offline

    Lightspeed

    What algorithm the x1-x2 and z1-z2?
    Cause if so theres a bit of a problem with this method.

    Ok Thanks to the wierd time I get ideas from people helping me I found that vec.subtract(vec); works . . . except for it's reversed(Now I was very lucky to find out this solution as if I subtracted it the other way it was off and incorrect the last time I tried).

    It still wont work correctly?

    Nevermind ahem I was right . . . I didn't export and refresh . . .

    Anyway I used ~x + 1 to get my "reversed" int.
     
    Last edited: Apr 12, 2016
  18. Offline

    mythbusterma

    @Lightspeed

    You do realise ~x + 1 is exactly the same statement as -x, right?
     
  19. Offline

    Lightspeed

    I need to completly reverse it both for positive and negatives.
    EDIT: Welp kewl thanks for the erm? Optimization?
     
  20. Offline

    mythbusterma

    @Lightspeed

    To be fair, I'm pretty sure what you did is how the computer will actually execute the instruction, but it certainly isn't more readable, and is probably quite confusing to the novice programmer.
     
Thread Status:
Not open for further replies.

Share This Page