Better doublejump

Discussion in 'Plugin Development' started by VortexGmer, Apr 5, 2015.

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

    VortexGmer

    Hi, I have the usual doublejump script here:
    Code:
        @EventHandler
        public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
            Player player = event.getPlayer();
            if (player.getGameMode() == GameMode.ADVENTURE) {
                player.setFlying(false);
                Location loc = player.getLocation().clone();
                player.playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
                loc.setPitch(0.0F);
                Vector vel = player.getVelocity().clone();
                int strength = 2;
    
                Vector jump = vel.multiply(0.1D).setY(0.3D * strength);
                Vector look = loc.getDirection().normalize().multiply(1.5D);
    
                player.setVelocity(jump.add(look));
    
                player.setAllowFlight(false);
    
                event.setCancelled(true);
            }
        }
    
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if (player.getGameMode() == GameMode.ADVENTURE) {
                if (!player.getAllowFlight()) {
                    Location loc = player.getLocation();
                    Block block = loc.getBlock().getRelative(BlockFace.DOWN);
                    if (block.getType() != Material.AIR) {
                        player.setAllowFlight(true);
                    }
                }
            }
        }
    But it doesn't exactly fit my needs, I need it to change the strength of the y depending on where the player is looking...
    This was pretty easy but the things with the why are sort of weird, Help please
     
  2. Offline

    dlange

    Code:
                    p.setVelocity(new Vector(p.getVelocity().getX(), 1.0D, p.getVelocity().getZ()));
    That's what i used for jump pads... I guess you can implement it to work with that. It launches the player to where they are facing.
     
  3. Offline

    VortexGmer

    That's a constant y power of 1, Not what I need....
     
  4. Offline

    dlange

    @VortexGmer i don't understand entirely what you are asking us to help you with though...
     
  5. What if you would use the following code for the y:
    Code:
    double mpitch = ((pitch + 90) * Math.PI) / 180;
                double myaw = ((yaw + 90) * Math.PI) / 180;
    Math.cos(myaw);
                double my = Math.sin(mpitch) * Math.sin(myaw);
    And you can then use the my for the height, multiplied by a certain number if you want.
    What this does is it gets the y value of the vector that he is looking at. But it bit more accurate than some bukkit methods for some reason with me.
     
  6. Offline

    VortexGmer

    for some reason this outputs a weird number when i do this:
    Code:
    
                double mpitch = ((player.getLocation().getPitch() + 90) * Math.PI) / 180;
                double myaw = ((player.getLocation().getYaw() + 90) * Math.PI) / 180;
                Math.cos(myaw);
                double my = Math.sin(mpitch) * Math.sin(myaw);
    
     
  7. What it could be that you need to do "(player.getLocation().getPitch() % 360)" instead of "player.getLocation().getPitch()", and the same for the yaw. It fixes the problem for some other people. And the "Math.cos(myaw);" you can remove it, I forgot to remove that.
     
  8. Offline

    VortexGmer

    sure
     
  9. Else you can try "player.getHeadLocation().getDirection()" to get a vector and get the y value from that.
     
  10. Offline

    VortexGmer

    But this doesn't work?
    Code:
                Location loc = player.getLocation().clone();
                player.playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
                loc.setPitch(0.0F);
                Vector vel = player.getVelocity().clone();
                Vector look = loc.getDirection().normalize().multiply(1.5D);
                double mpitch = ((player.getLocation().getPitch() % 360 + 90) * Math.PI) / 180;
                double myaw = ((player.getLocation().getYaw() % 360 + 90) * Math.PI) / 180;
                double my = Math.sin(mpitch) * Math.sin(myaw);
                player.sendMessage(my + "");
                Vector jump = vel.multiply(0.1D).setY(my);
     
  11. Maybe instead of player.getVelocity(), use loc.getDirection(); and you need to set the velocity of the player. Also if this still doesn't work, what doesn't work? Where does it go wrong?
     
  12. Offline

    VortexGmer

    SO on Vector vel = loc.getDirection();?
     
  13. I think so, but it's hard to know for sure, because I don't know what doesn't work exactly.
     
  14. Offline

    VortexGmer

    Also why it didn't work was when the player was facing east it was like 0.7818731 and when they were facing west it was the negative of that and different looking of y axis was all messed up!
     
  15. I see it, you need to use Math.cos(mpitch); to calculate the my. Sorry, the code I used was having the z axis up and the y axis to the back.
     
  16. Offline

    VortexGmer

    ok
     
Thread Status:
Not open for further replies.

Share This Page