launch pads not launching...

Discussion in 'Plugin Development' started by bling4525, Aug 27, 2015.

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

    bling4525

    So I just finished building the spawn for my server and I wanted to write a plugin to launch players into the air. When I tried my code, it just launches the player directly forwards. While many other threads examine this issue, I haven't found a way in which it actually works. So far I have tried:

    Multiplying player.getDirection() vector by 10 and launching the player along it
    Multiplying player.getDirection() vector by 10, adding to the y value and then launching
    Both of those things with player.getEyeLocation().getDirection()
    Creating two different vectors, one which defines a large y value and one with getDirection() multiplied by 10, then launching the player on both vectors simultaneously

    Here is what I have so far:
    Code:
    @EventHandler
                public void launchPlayer(PlayerInteractEvent JumpPadPressed) {
              
                      if(JumpPadPressed.getAction().equals(Action.PHYSICAL)){
              
                          Player player = JumpPadPressed.getPlayer();      
              
                          if(JumpPadPressed.getClickedBlock().getType() == Material.STONE_PLATE && player.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.GOLD_BLOCK){
                    
                              Location loc = player.getLocation();
                            
                              PacketPlayOutWorldParticles packetParticle = new PacketPlayOutWorldParticles(EnumParticle.SMOKE_LARGE, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), 0, 0, 0, 1, 0);
                              ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetParticle);
                            
                              Vector launch = player.getLocation().getDirection().multiply(10);
                            
                              player.sendMessage("pre-launch vector y value: " + launch.getY());
                              launch.setY(2.0D);
                              player.sendMessage("post-launch vector y value: " + launch.getY());
                            
                              player.setVelocity(launch);      
                              player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
                
                  }
            }
        }
    From the print statements I figured out something interesting: if I look straight down, the pre - launch y value is equal to -10 and I don't even shoot forwards. If I look straight up, the pre - launch y value is equal to 10 and I don't shoot forwards. Anywhere in between gives me a y value based on the angle of my head, and with me looking straight forward, one equal to 0.

    regardless of what the pre - launch y value was the post - launch one is always 2.0. It doesn't make a difference anyway, the launch pads are stubbornly refusing to launch me upwards.
    I am all out of ideas at this point. Please help!
    Thank you!

    - Bling4525

    Edit: I tried creating a vector that world launch the player only straight up. I made a new vector(player.getVelocity().getX(), 2.0D, player.getVelocity().getZ()); and launching myself on it. It doesn't do anything. The weird bit is that I created a plugin not long ago that allows you to whack a sheep and send it flying up into the air, using exactly the same code, and it works fine. Help?

    it seems as though setting the y vector of a player does nothing.
     
    Last edited: Aug 27, 2015
  2. Offline

    meguy26

    I could be completlet wrong here, I'm on my tablet, but I'm pretty sure what use for double jumps is:
    Code:
    somePlayer.setVelocity(somePlayer.getVelocity.multiply(2));
    Hopefully those methods actually exist.....

    In theory you could use the same code, just with a different multiply value or trigger,

    @bling4525
     
    bling4525 likes this.
  3. Offline

    au2001

    @meguy26 Well getVelocity isn't a variable but a method: getVelocity()
    And if the player isn't moving it wouldn't be fun.

    Better use
    Code:
    Player.getEyeLocation().getDirection().normalize().setY(1)
    EDIT: If you want the player to go straight into the air, use:
    Code:
    Player.getVelocity().add(new Vector(0, 1, 0))
    (and don't forget to Player.setVelocity() afterwords)
     
    Last edited: Aug 28, 2015
    bling4525 likes this.
  4. Offline

    meguy26

    @au2001
    What I posted will work, except not in the way the OP is asking, my code launches the player in the direction they are looking, and the OP wants to launch the player directly up.

    Hopefully you're code works for the OP
    :)
    I was too tired when I posted my answer.


    EDIT:
    @bling4525
    Excavated some code of mine and found something that should work:
    Code:
    //Checks and particles and stuff here
    Player p = putYourPlayerHere;  //Your player variable
    Location one = p.getLocation();
    Location two = p.getLocation().add(0, 5, 0); //Change the 5 to higher or lower number to change the speed of the launch
    Vector vec = two.toVector().subtract(one.toVector); //Calculate the vector
    p.setVelocity(vec); //Launch the player
    This method uses a technique I learned a while back in which you can use vector subtraction to launch an entity from one location to another, in this case we launch the player towards a location directly above them.
     
    Last edited: Aug 28, 2015
    bling4525 likes this.
  5. Offline

    au2001

    @meguy26 That's a very complicated method for a such simple thing...
    Code:
    new Vector(0, 3, 0)
    Will do what your code does (but you have to play with the values to get the right power).
     
    bling4525 likes this.
  6. Offline

    bling4525

    thanks all!

    will look into each of these answers.

    Edit: @au2001 I tried the code you provided, but when I sprint over the pressure plate, I just pause for a second and then keep moving.

    @meguy26 When I used your code, occasionally if I sprint - jumped directly on top of the pressure
    plate it would launch me nicely into the air. However, most other times I would receive the same results as the previous.

    I now know how to launch players straight into the air... how can I launch them in an arc?
    Is there any more consistent way to get players launched? It would only work if I jumped onto the pressure plate from a higher block.

    bump...

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

    au2001

    @bling4525 Can we see the code you used? It should work.
     
  8. Offline

    bling4525

    @au2001 here it is.

    Code:
    public void launchPlayer(PlayerInteractEvent JumpPadPressed) {
              
                      if(JumpPadPressed.getAction().equals(Action.PHYSICAL)){
              
                          Player player = JumpPadPressed.getPlayer();      
              
                          if(JumpPadPressed.getClickedBlock().getType() == Material.STONE_PLATE && player.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.GOLD_BLOCK){
                    
                              Location loc = player.getLocation();
                            
                              PacketPlayOutWorldParticles packetParticle = new PacketPlayOutWorldParticles(EnumParticle.PORTAL, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), 0, 0, 0, 1, 0);
                              ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetParticle);
                            
                              Vector launch = player.getLocation().getDirection().multiply(5);
                            
                              Player p = player;  //Your player variable
                              Location one = p.getLocation();
                              Location two = p.getLocation().add(0, 2, 0);
                              Vector vec = two.toVector().subtract(one.toVector()); //Calculate the vector
                            
                              p.setVelocity(launch);
                            
                              vec.setX(player.getVelocity().getX());
                              vec.setZ(player.getVelocity().getZ());
                            
                              p.setVelocity(vec); //Launch the player
                            
                              player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
                
                  }
            }
        }
     
  9. Offline

    au2001

    @bling4525 Instead of:
    Code:
    player.getLocation().subtract(0, 1, 0).getBlock()
    Use:
    Code:
    JumpPadPressed.getClickedBlock().getRelative(BlockFace.DOWN)
    (Your code gets the block under the player, but you can activate a pressure plate while standing on the block next to it)

    And replace all this code:
    Code:
    Vector launch = player.getLocation().getDirection().multiply(5);
                      
    Player p = player;  //Your player variable
    Location one = p.getLocation();
    Location two = p.getLocation().add(0, 2, 0);
    Vector vec = two.toVector().subtract(one.toVector()); //Calculate the vector
                      
    p.setVelocity(launch);
                      
    vec.setX(player.getVelocity().getX());
    vec.setZ(player.getVelocity().getZ());
                      
    p.setVelocity(vec); //Launch the player
    By:
    Code:
    player.setVelocity(player.getVelocity().add(new Vector(0, 1, 0)));
    To launch him straight into the air, or to launch him a bit forward:
    Code:
    Vector velocity = player.getEyeLocation().getDirection().normalize();
    player.setVelocity(velocity.setY(1)));
     
    Last edited: Aug 29, 2015
  10. Offline

    bling4525

    thank you! didn't get around to testing but will do so now.
     
Thread Status:
Not open for further replies.

Share This Page