Vector problem

Discussion in 'Plugin Development' started by MattTheBeast, Jul 12, 2017.

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

    MattTheBeast

    For some reason I feal like this is simple but I just cant understand xD.

    Here is the problem: Lets say I have 2 locations (Location a, Location b), when location a changes, if its distance is lets say 5 blocks from location b, location b needs move towards location a and the direction of location b must be facing location a.

    Sorry if this is confusing xD its confusing me a lot, id appreciate is someone who is good at this can help me out here.
     
  2. Offline

    PhantomUnicorns

    Are you making an AI? How are you detecting movement? How are you saving the locations?

    I'm guessing location A is a player/entity. And location B is a custom mob that could be anything
     
  3. Offline

    MattTheBeast

    @PhantomUnicorns I'm actually trying to make a dragon pet that follows you, its made of armorstands, the location of the dragon is its center location. I can detect if the owner moved with a repeating runnable.

    Thanks for reply that was fast xD

    Lets say this is in the runnable

    If(Owner.getLocation().distance(dragon.getLocation()) > 5){
    dragon.move(Owner.getLocation); //?? How would I make this methode?
    }

    As the dragon moves his direction must be facing the player
     
    Last edited: Jul 12, 2017
  4. Offline

    PhantomUnicorns

    Hmm, this is a hard one because it's the core of a plugin that's pretty complex. You would have to set the direction of the ender dragon to the player and find a way to make it seem natural (for both movement and facing) but other then that: I think it would be better if you made a custom ender dragon class. Because looping through players is slow, I would create an arraylist of the custom enderdragons to have on hand. But inside the custom ender dragon, set it's pathfinder goals, after this I'm no longer able to help because I suck at vectors :p
     
  5. Offline

    MattTheBeast

    No, its gonna be a mini dragon, and il make it out of armorstands. Anyways as im trying to explain my problem I'm slowly understanding. Il put a gif on here of what I'm trying to explain when its solved xD

    Thanks for the help

    Il make the problem simpler:

    How do you make a locations direction face a other location?
     
    Last edited: Jul 12, 2017
  6. Offline

    Zombie_Striker

    @MattTheBeast
    For this, let me show you the math needed. If you have done vectors (should be taught in Algebra), then most of the math should be familiar:

    First, we need to describe the change in A as a vector. That will be represented by ∆A:
    A₂ - A ₁ = ∆A

    From there, all you need to do is add the vector to B. If you use the vector object, you can just use Location#add(Vector) to add it.
     
  7. Offline

    MattTheBeast


    Oh I understand now ty
     
Thread Status:
Not open for further replies.

Share This Page