Calculating Arrow Aiming

Discussion in 'Plugin Development' started by Ziden, Jul 5, 2012.

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

    Ziden

    Hi there.
    This is a hard question i dont know if anyone knows how to answer it, calling it to the code/math gods.

    I think its something really usefull to know how to do is to know how to shoot arrows precisely.

    Lets say i have 2 locations, A and B.

    How could i know the correct Vector for an arrow velocity to start from A, and land in B ? My math knowledge is bad :(

    Thanks in advance.
     
  2. Offline

    zajacmp3

    That's hard really...
    You would be satisfied with a vector that will be a straight line? Or you want an equation that will get you exactly the way that arrow goes? First should be easy. And I should be able to give you a equation how to calculate this or better give you an algorithm. I will keep this in mind cause I need to think a bit and search here and there. Additional variable Z (from X, Y, Z) is making this tricky for me.
     
  3. So you want to shoot an arrow from your location and make it land at the location you're pointing at ?
    http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
    First read the "Notation" part and gather the data... gravitational force, velocity of arrow, etc, I have no clue if Minecraft has the same gravitational force as reality, you could test it... and as you're shooting the arrow yourself, you know the velocity, height and stuff.
    Anyway, after you have those values, read "Angle required to hit coordinate (x,y)" and you should be able to calculate the angle which you need to shoot the arrow to make it land at the specified location :)

    Sorry I can't be much help here tough xD at least you have a lead until someone good at math comes in :p
     
    ferrybig likes this.
  4. Offline

    andf54

    You heretic! You should be praying to the physics gods!

    Its an interesting idea. You can even make an api for this. It can fire an ArrowTargetCalculationEvent or just attach the trajectory to arrows metadata.

    Trajectory of an object is determined by initial speed, angle and gravitational constant (assuming no friction). Its very easy to calculate the trajectory from those parameters. However, I doubt that mc has correct physics. And even if it does, we still need the correct gravitational constant.

    I can help you, but I need you to do some experiments.

    Use a scheduler and record the coordinates of an arrow every second (fraction of a second if not enough data points) and send me the results.

    The results should be in the format:
    [ [x1, t1], [x2, t2], ... ] for motion parallel to the ground. Make sure you fire the arrow in x direction.
    [ [y1, t1], [y2, t2], ... ] for motion perpendicular to the ground.

    Also, I need to know how mc velocity actually translates. I need you to give me arrow.getVelocity().getX() and arrow.getVelocity().getY() for each previous data set when arrow is fired.

    Hopefully the results will help to determine how mc projectile physics works.

    If you need further help or dont understand something, then pm me your skype/msn.
     
  5. Offline

    Ziden

    Whats your msn ?

    Ill make a 'debug' plugin as you sayd and ill send you. I dont undersand fully what u want but i think i can do it.

    If you want add me @ msn [email protected] ^^ We can make the API.

    Ive made a simple plugin to test it

    Please let me know what i have to change

    the plugin tracks the arrow for 10 seconds, giving you its physical location and its speed vector

    https://dl.dropbox.com/u/15644623/ArrowPhysics.jar
     
Thread Status:
Not open for further replies.

Share This Page