Enderpearl Trajectory

Discussion in 'Plugin Development' started by GusGold, Nov 10, 2013.

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

    GusGold

    I've never looked at the actual code behind enderpearls flight path, but are the close to reality.
    Do they follow a parabolic flight path?
    Are they effected by deceleration (does mc emulate slowing due to friction)?
    Does the initial velocity stay relative to the player, or to the earth (If I run and throw, does it go further than standing still)?
    And finally, what would be the easiest way to find its collision point (i'm not fussed about entities, just blocks for now)?

    Thanks.
     
  2. Offline

    GusGold

    *shameless bump*
    Any ideas or suggestions?
     
  3. Offline

    Garris0n

    Do they follow a parabolic flight path? - I don't even know what that means.
    Are they effected by deceleration (does mc emulate slowing due to friction)? - Yes...kind-of
    Does the initial velocity stay relative to the player, or to the earth (If I run and throw, does it go further than standing still)? -Earth
    And finally, what would be the easiest way to find its collision point (i'm not fussed about entities, just blocks for now)? - http://forums.bukkit.org/threads/tutorial-get-the-block-where-a-projectile-landed.176395/

    https://github.com/Bukkit/CraftBukk...t/minecraft/server/EntityProjectile.java#L164
    Read that.
     
  4. Offline

    GusGold

    Garris0n
    Thanks for the other info
    If I throw it from height y1 (and position x1) and it reaches a height of y2, and then lands at y1 (of position x2) again. y2 should be at the position of (x1 - x2) /2. Wikipedia article for more info:http://en.wikipedia.org/wiki/Trajectory#Range_and_height


    Explain... :p
     
  5. Offline

    amhokies

    It means is the flight path in the shape of a parabola, and the answer is yes.
     
  6. Offline

    GusGold

  7. Offline

    Vexil

    If you're looking to find where the enderpearl is thrown from, just use a ProjectileLaunchEvent, check to see if the projectile's shooter is a player, and if the projectile is an enderpearl, then save the location or do whatever.
    Code:java
    1.  
    2. @EventHandler
    3. public void enderpearlThrow(ProjectileLaunchEvent e) {
    4.  
    5. if(e.getEntity() instanceof EnderPearl && e.getEntity().getShooter() instanceof Player) {
    6.  
    7. Player p = (Player) e.getEntity().getShooter();
    8.  
    9. /* do whatever */
    10.  
    11. }
    12.  
    13. }
     
  8. Offline

    GusGold

    Vexil
    I meant, as soon as the player throws it, find where the enderpearl will end up hitting. I guess I could emulate the flight in one tick?
     
  9. Offline

    Vexil

    That may be a small bit more difficult than it seems. You would have to calculate the flight of the enderpearl. Have you looked at the source to find out exactly how the trajectory is calculated?
     
  10. Offline

    GusGold

    Yes!
    ...no
     
  11. Offline

    Vexil

    You are going to have to do a bit of math. I would look for a mod that has a trajectory shower for enderpearls, kind of like a line that goes from your location to where the mod has calculated the enderpearl to land, and look at the source code. Otherwise try to preform some tests in game with adjusting your angle. I would play with vectors if I were you.
     
  12. Offline

    GusGold

    Vexil
    I'm thinking I might just use nms and iterate through the flight path. Do you reckon that would be too much to process in a game tick?
     
  13. Offline

    Vexil

    Well, considering NMS does it, probably not unless a lot of people are spamming enderpearls.
     
  14. Offline

    GusGold

    Vexil
    Enderpearls will be a rarity where I will be using this, so hopefully that will moderate it. Are you able to help with the nms part (nms virgin here :3)?
     
  15. Offline

    Vexil

  16. Offline

    maxben34

    What are you using this for? You can set the velocity of a thrown projectile, such as an enderpearl. You can use some equations to get the vector velocity coordinates and then set the velocity to that new vector.
     
  17. Offline

    GusGold

    maxben34
    I don't want to change it. I just want to predict where it will land, as it is being shot :)

    Vexil
    I have CB's NMS' EntityProjectile open in eclipse and it is not even similar apart from some of the methods to the git hub

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  18. Offline

    maxben34

    If you have a preset velocity you can get the location where it's launched and the set velocity and then get the final location of that. I'm pretty sure you're looking at a parabolic trajectory here.
     
    Vexil likes this.
Thread Status:
Not open for further replies.

Share This Page