Do Vectors represent meters per second?

Discussion in 'Plugin Development' started by HelpMeILostMyAccount, Jul 30, 2019.

Thread Status:
Not open for further replies.
  1. I am trying to calculate the trajectory of an arrow being launched, and I'm having trouble understanding the Vector class. Just for experimenting, I'm making a program that will calculate the exact velocity to send my arrow with at 45 degrees in the X-Y plane, accounting for 9 m/s^2 of gravity in Minecraft. If I want my arrow to land 20 meters away from my player in a flat piece of land in a 2D vector, the velocity would be "20 * 9 * sin( 2 * 45 )" which is about 13.4.

    I want to send the arrow flying at 45 degrees, because the velocity was calculated as such. So, the X and Y values of my arrow's vector should be a square to make 45 degrees. That would be "velocity / sqrt( 2 )". The velocity being 13.4, this was about 9.48. So I sent my arrow flying at a Vector of (9.48, 9.48, 0.0). However, it really didn't work at all. And I believe I have made a mistake in assuming that a Vector's length is the travel speed in meters per second. What can I change in my calculations?

    Code:
    if (cmd.getName().equalsIgnoreCase("launch")) {
    
        Player playerSender = (Player) sender;
    
        double targetDistance = Double.valueOf(args[0]); // meters
        double gravity = 9;  // m/s^2
    
        double resultingVelocity = Math.sqrt( targetDistance * gravity * (1 / Math.sin( 0.5 * Math.PI )) );
        double vectorValue = resultingVelocity / Math.sqrt( 2 );
    
        Vector arrowLaunchVector = new Vector(vectorValue, vectorValue, 0.0);
    
        playerSender.launchProjectile(Arrow.class, arrowLaunchVector.normalize());
    
        return true;
    }
    
     
    Last edited: Jul 30, 2019
  2. Offline

    Machine Maker

    So I think the Vector class only represents a change in location relative to a position. When you construct a new one, its basically just an X, Y, Z relative to 0,0,0.

    EDIT: Messing around with a few projectile motion calculators online, I can't seem to get a solution that fits your inputs.

    An object fired at 13.4 m/s will never be able to go 20m on a flat surface regardless of the angle.

    The max distance it will go is 18.3m if fired at 45 deg.

    You would have to fire at just over 14m/s at 45deg to go 20m. So I think you did a bit of math wrong.
     
    Last edited: Jul 30, 2019
  3. Offline

    Kars

    Likely. In Minecraft things are hardly ever measured in units per second. If something is measured its usually measured in ticks but mostly you have to invent measurements yourself.
     
  4. @Machine Maker The velocity is the dependent here. I want the calculations to accommodate velocity for the inputted range I desire.
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. The equations I'm using give me velocity in meters per second. But I need to make this usable in Minecraft. Is there a reference for me?
     
  7. Offline

    Machine Maker

    @HelpMeILostMyAccount Try normalizing the vector (like you already are) and then multiply the vector by the speed.
     
  8. Offline

    timtower Administrator Administrator Moderator

    What is a meter in minecraft? A block right? So it already is.
    That would result in the same vector though.
     
  9. No, but you see, from what I know, a vector just represents a relative direction from one position to another position. Launching an arrow with a vector of 5 in the X direction doesn't mean the arrow will be launched at an initial velocity of 5 meters per second. I need a conversion
     
  10. Offline

    timtower Administrator Administrator Moderator

    Then what do you define as a meter? What speed does it have then when you shoot at with a vector of 5?
     
  11. Offline

    Machine Maker

    Derp.

    ^^^ that was a facepalm emoji on my phone.
     
  12. I want 1 meter per second to be 1 block per second. I'm trying to read up on the trajectory of arrows.

    EDIT: Alright, looks like a fully charged arrow will go at about 52 blocks per second
     
  13. Offline

    WI5E

    No, it's relative to whatever vector it's being applied to. 0, 0, 0 can be one of them, but not the only one exclusive to it.
     
  14. Offline

    Machine Maker

    @WI5E Isn't that what I said? When you do new Vector(x, y, z) its relative to 0,0,0 right?

    But it can be relative to other positions as well, just not when you (key word) construct a new one.
     
Thread Status:
Not open for further replies.

Share This Page