Throw up a player in the air

Discussion in 'Plugin Development' started by xLoGiiKzZo, Jul 13, 2013.

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

    xLoGiiKzZo

    How would I throw up a player in the air like a golem does? I'm confused by how this vector stuff works.
     
  2. Offline

    chris4315

    Here you go:

    Code:java
    1.  
    2. Player player = (Player) someplayer; // Get a player by some means.
    3. player.setVelocity(new Vector(0,1.5,0));
    4.  
     
    bobacadodl likes this.
  3. Offline

    xLoGiiKzZo

    chris4315
    Does not work.

    EDIT: The code gets executed when a player is punched, and it doesn't work unless the player is punched about 2-4 times within a very short time.
     
  4. Offline

    xTrollxDudex

  5. Offline

    xLoGiiKzZo

  6. Offline

    xTrollxDudex

    xLoGiiKzZo
    Yes event, sorry. Stupid autocorrect.
    Why can't you use player damage event and check if event.getDamager() instanceof Player then propel him upwards?
     
  7. Offline

    xLoGiiKzZo

    xTrollxDudex
    Because that event doesn't exist... Am I getting trolled here? :3
     
  8. Offline

    xTrollxDudex

    xLoGiiKzZo
    Lol I don't even know why it's not there. Nvm
     
  9. Offline

    ZeusAllMighty11

    I don't understand your issue.
     
  10. Offline

    chris4315

    Edit the y velocity (the 1.5) and make it to your pleasure.

    If it takes 3-4 hits then you're lagging.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
    bobacadodl likes this.
  11. Offline

    xTrollxDudex

    chris4315
    Lrn2edit
    TheGreenGamerHD
     
  12. Offline

    ZeusAllMighty11

    xTrollxDudex

    That's not what I mean. I don't understand his issue of 3-4 hits. Should be executed every hit.
     
  13. Offline

    xTrollxDudex

  14. Offline

    jayfella

    Actually I believe this is a bit of a glitch. Try setting the vector to a variable and pass the variable to the .setVelocity method. I remember pulling my hair out for the same thing.
     
  15. Offline

    bobacadodl

    that makes no sense

    Code:
    @EventHandler
    public void onHit(EntityDamageByEntityEvent e){
    if(e.getEntity() instanceof Player){
    Player hit = (Player)e.getEntity();
    hit.setVelocity(new Vector(0,1.5,0));  // CHANGE THESE NUMBERS TO YOUR LIKING! INCREASE Y VELOCITY
    }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  16. Offline

    jayfella

    bobacadodl I never said it did make sense, I only stated a fact. There are numerous java bugs that "dont make sense" - this is one of them.
     
  17. Offline

    LazyLemons

    xLoGiiKzZo setVelocity() does weird things like that sometimes. I'd recommend doing this:
    Code:java
    1.  
    2. Player p = ...
    3. ((CraftPlayer)p).getHandle().motY = 1.5;
    4.  

    That should work better and never do the "3-4 hits" thing you mentioned.
     
  18. Offline

    xLoGiiKzZo

    bobacadodl jayfella chris4315

    Still not working. Here's my code:

    Code:java
    1. @EventHandler
    2. public void onPunch(EntityDamageByEntityEvent e){
    3. if ((e.getEntity() instanceof Player) && (e.getDamager() instanceof Player)){
    4. Player damagee = (Player) e.getEntity();
    5. Player damager = (Player) e.getDamager();
    6. Vector vector = new Vector(0,1.5,0);
    7. damagee.setVelocity(vector);
    8. damager.sendMessage("Thrown");
    9. }
    10. }


    I'm not lagging btw.

    EDIT: Yes I've tried changing the Y velocity.
     
  19. Offline

    bobacadodl

    Does it move them at all? If it does, try increasing the 1.5 value to something higher, such as 10, and see if that changes anything.
     
    xTrollxDudex likes this.
  20. Offline

    xLoGiiKzZo

    bobacadodl
    Well they move just like they would when they get punched (they get knocked back a little). Something else I noticed was that they only get thrown up if I punch them once and then again while they are still being knocked back and up from the punch.
     
  21. Offline

    xTrollxDudex

    xLoGiiKzZo
    I don't think you can setVelocity() to a player. It is undefined :/ for type player
     
  22. Offline

    xLoGiiKzZo

    xTrollxDudex Your trolling is only bumping my thread, which means you're helping me.
     
  23. Offline

    xTrollxDudex

    xLoGiiKzZo
    I'm not trolling you -_-

    Edit: you know what? If you don't appreciate my help, I'll just leave. Your maturity is very low.
     
  24. Offline

    xLoGiiKzZo

    Well I think I found out the problem. If I cancel the event before I apply the new vector, it works perfectly. If I don't cancel it, then it doesn't. I think its because of the vector that gets added to the player by default.
     
    bobacadodl likes this.
  25. Offline

    Garris0n

    Yeah this happens, I remember running into that bug a while back. Didn't remember it reading this thread 'til I saw this post. I didn't need the damage anyway, just the effect, so I cancelled the event, made it set the vector, and damaged the player 0, but you could always damage them from whatever the hit was and it should work.
     
  26. Offline

    xLoGiiKzZo

    Garris0n
    Yea thats what I did. Just cancelled the event and then used player.damage(damage);
     
  27. Offline

    xTrollxDudex

    xLoGiiKzZo
    Code:java
    1. player.damage(event.getDamage());

    Hope you don't call me a troll again because I'm helping you
     
  28. Offline

    xLoGiiKzZo

    xTrollxDudex
    I didn't have a problem with that?
     
  29. Offline

    xTrollxDudex

    xLoGiiKzZo
    That would make everything the same damage? A punch then equals the damage of a diamond sword
     
Thread Status:
Not open for further replies.

Share This Page