Solved Damage players when falling on them

Discussion in 'Plugin Development' started by EcMiner, Apr 30, 2013.

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

    EcMiner

    Hey, is there a way that, when you jump on a player you hurt the player you fell on?
     
  2. Offline

    Nitnelave

    Not really. If you really wanted it, you would have to listen to onPlayerMove, then log when a player is falling, and do your own entity collision code (might be complicated), then deal the damage yourself.
     
  3. Offline

    EcMiner

    Do you have any experience with player collisions, so yes, would you help me please?
     
  4. Offline

    soulofw0lf

    the colision is the easy part....
    Location falling = player1.getLocation();
    Location target = player2.getlocation();
    Double hit = falling.distance(target);
    if (hit <= 2)]
    do stuff
     
  5. Offline

    Nitnelave

    I would like to try to discourage you from doing this, as it will be very expensive for the server. But if you really want to (and it WILL be buggy at first, if not forever) : onPlayerMove, check the nearbyEntities, get the players, and then you have to check that the feet of the first one are at the same spot as the second one's head, and he is falling (check out the getFallingDistance method, I'm not sure how it works).
    To do that, well, you would have to check that the altitudes match (absolute value of (playerFalling.getY() - other.getY() + playerHeight) < small_threshold), and that the x/z also match (this is going to be a bit more complicated, unless you only want approximation and check that the distance between them ((x2 - x1)² + (y2 - y1)² < threshold) is small). If you want to do it right, take a sheet of paper, draw two squares at an angle (the yaw of the players) and see what you have to check to see if they overlap, if you are confident in your maths level.

    I disagree... Every time you would walk next to someone, he would get hurt.

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

    Thej0y

    Like this? : stomper
    Just saying that in case you wanted this fonction only ;) but if its for a larger project, the author doesnt give sources :(
     
  7. Offline

    soulofw0lf

    that's just the actual collision part of it, you still need a listener to detect that your feet are above the players head with the movement....
     
  8. Offline

    EcMiner

    Thanks all for your support, i managed to get it working :)
     
Thread Status:
Not open for further replies.

Share This Page