Getting all locations between two locations

Discussion in 'Spigot Plugin Development' started by jimbo8, May 16, 2015.

  1. Hi there!

    So, I am currently developing a hidden feature for me and my girlfriend; whenever we get within 5 blocks of radius, a line of hearts are going to occur between us. Now, to do this, I need to get the locations(XYZ) within the two locations, without the location being a square, because it is supposed to be a line, not a bunch of hearts in a square.

    I have tried with vectors, though you cannot convert vectors to XYZ-coordinates, which is needed to spawn particles.

    Any ideas? Thanks!
    • Creative Creative x 3
  2. If you want a line between the two points, generate it ;) You have the desired begin and end-point, can derive a point and a direction from that, and now just need to sample the line in a step-width of your choice between 0 and 1.

    Where exactly does your problem lie with Vectors? You can indeed retrieve their X-,Y- and Z-Parts, or turn them into a location, they offer methods for both those operations.
  3. @dxdy

    Oh, I didnt' know that I could retrieve the vector's actual location, and not only the vector position. How would I do this, what are the methods called? Any pseudo code?

    Thanks for such an fast answer.
  4. Well, a 3d-vector denotes a point in the space. A Location represents a point in a specific Minecraft world. So you can turn a Vector into a Location by providing it with a world.

    Code (Text):
    Vector v;
    Location l = v.toLocation(world);
    • Like Like x 1
  5. @dxdy

    Well, I am atleast one step closer.

    Though, the Vector#toLocation-method does not return as an array or an list; how would I then get all the locations inbetween if I don't have a list of locations to go through?
  6. For a basic implementation you'll do the following. Get the start-point (your position) and the end-point (her position). Then, get the vector between those points (b-a) and call it d. You now can get points on the line through the equation p = a + d * r; where r is a floating point number between zero and one (you could go beyond that, but you want only points on the segment inbetween you two). Now you can sample points along that line (for example, go from 0 to 1 in increments of 0.1) to get blocks you'll have to set to get a line to appear.
    • Like Like x 1
  7. @dxdy

    Thank you so much, works like a charm!

    Now, to a bit different question; do you know if it is possible to make the hearts not go upwards like they usually do?

    Because now, it looks like this:


    and I want it to only be one heart, if that makes sense. Not make it look like a billion trillion hearts on top of eachother.
  8. What exactly do you mean by that? Do you want to have one heart going from you to her (or vice-versa)? Or do you want to stop all those hearts on the picture from drifting upwards?
  9. @dxdy

    I want to stop all the hearts from drifting upwards. It makes it look really weird.
  10. From the screenshot it looks like instead of generating the line of hearts once every time she gets into the range, you're generating a line every single tick when she's in the radius. That would explain why so many of those hearts appear.
  11. @dxdy

    Yeah, that's the point; I want to have a constant line of hearts between us, but if I wait 20 ticks, then the hearts appear a way too rarely.

    Eventually, sending only one heart from me to her or vice-versa could be a solution to this, that would be even nicer, actually.

    Edit: Doing that would still make the heart go upwards every time we move it one location forward, though.
  12. To send one object on the line, simply update its position and velocity regularly while increasing the r.
    • Like Like x 1
  13. Sorry for the unrelated comment, but this is probably the smartest and sweetest things I've ever seen.

    She's a keeper ;)
    • Agree Agree x 2
    • Like Like x 1
  14. Thanks!

    This is how it ended:


    Thanks everyone! <3
    • Like Like x 3
    • Friendly Friendly x 2
  15. Hey @jimbo8,

    Could you post the code of how you solved this ?

    Thanks !
    • Like Like x 1
  16. Necro much? This from May 17th 2015..
    • Agree Agree x 1
  17. Don't necro something this old, just PM the guy please.
  18. Sorry didn't know it was such a deal if someone asked for something
  19. Asking questions isn't a bad thing, but this thread is a year old, posting in it brings it back to the top of the thread list.
    • Agree Agree x 1
  20. Next time you "don't know" if something is such a big deal (Especially necro'ing something from over a YEAR ago) Check the forum rules? Bumping something from that long ago takes it RIGHT to the top of the list, rendering it useless since the OP got required assistance when it actually mattered. PM the guy next time, rather than taking a thread-spot for a question that can very easily, be done in PM.

    Edit: Ninja'd by @Assossa ;-;