ArmorStand from block to block

Discussion in 'Spigot Plugin Development' started by iStokBroodje, May 23, 2017.

  1. Hi Guys,

    I'm developing a Ride plugin. But I need to know how I could make a ArmorStand move with ( CraftArmorStand)AS).getHandle.setPosition = new loc etc. And that from block to block. As seen under here:

    [​IMG]

    I got now clue anymore, I'm trying it now for 4 hours, and I just can't get a idea. And please don't do: Block1.getLoc - Block2.getLoc because it needs to be smooth and it will go over all blocks. Already thanks.

    - iStokBroodje
     
  2. 1. Decide how fast you want it to go. Let's say 0.1 blocks per tick.
    2. Every tick, see if you've reached your destination. If you are less than 0.1 blocks away from your next waypoint, switch to the waypoint after that one and proceed.
    3. Calculate the velocity vector for this tick. This starts as you have above, calculate the direction vector from current location to next waypoint (block1 - block2 or whatever). But then you scale it, simply like .normalize().multiply(0.1), where 0.1 is your speed in blocks/tick.
    4. Either apply that velocity to the armor stand, or use the velocity to calculate the next position (current loc + velocity) and teleport the armor stand. Either will work, and both should appear smooth since the client interpolates teleports, so which way you go is up to you.

    Hope that helps!
     
    • Friendly Friendly x 1
  3. By "to high" do you mean "too difficult" or "too resource intensive"?

    What is your background in mathematics?

    To begin I'll try restating what @NathanWolf said in a different manner
    1. First create a list of "waypoints" these are locations where you want your general direction to change "turning points" or where you want to change speed.
    2. Next you will create a way of traveling between theses waypoints, the easiest way to do this: you will have to create a vector (do you know what a vector is?) from your current waypoint to your next (see nathanwolf's #3), until you have arrived (or are relatively) close to your next waypoint, at this time you move forward through your list of waypoints and make your "next" waypoint your current waypoint, and move towards the following waypoint.
    Do you understand the idea and what to do, OR do you understand the idea but not how to code it, OR are you completely confused?
     
    • Agree Agree x 1
  4. Its not hard for me to understand how the coding works but I get confused at the vector. I just don't understand how I would travel from point to point with a vector. And I now what vectors are but most of the time I use them to make circle etc.
     
  5. "Its not hard for me to understand how the coding works" -> "I just don't understand how I would travel from point to point with a vector." makes sense ... xD
     
  6. sorry, I mean I'm not like a noob into coding but just vectors make me freak out. And thats what I'm trying to understand right now.
     
  7. and the thing I just can't understand is how I would let the armorstand move one point to the other. Do I need to do this:
    Code (Text):
    OldPoint - NextPoint
    When I do that I will only have the difference between those points.
     
  8. I dunno why everyone gets so scared about vectors. A vector is really just a line segment rooted at 0,0,0. Or, even more simply, it's just a set of coordinates.

    If you need to, sit down with a pen and paper and sketch this out in 2D. Draw how you think the armor stand would move along its path from tick to tick. Draw lines between those points- those are your velocity vectors.

    Maybe re-read my post and/or stormtrooper's follow-up, and then see if you have any questions about it. It's hard for us to really help you further when you've been given very concise step-by-step instructions but haven't really commented on any of it.
     
  9. Alright I will now just test something around and if I have like more correct questions I will tell.
     
  10. #12 stormtrooper28, May 24, 2017
    Last edited: May 24, 2017
    • Like Like x 1