1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to properly use knockBack()?

Discussion in 'Development' started by BouncyJeffer, Jun 22, 2017.

  1. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    I have the following code in my plugin and for some reason it's not working, I'm not receiving any errors but here it is.
    PHP:
            $x $event->getPlayer()->getX();
            
    $z $event->getPlayer()->getZ();
            
    $minZ 1516;
            
    $maxZ 1512;
            
    $minX 48;
            
    $maxX 52;
            if(
    $minX <= $x and $x <= $maxX and $minZ <= $z and $z <= $maxZ){
                
    $event->getPlayer()->knockBack($event->getPlayer(), 05015053);
            }
    Am I doing something wrong, or can someone give me an example of how to use it properly?
     
  2. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Oh and, my goal of this is to push a player whenever they walk within certain coordinates.
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The parameters of knockback are damager, damage, x, z and base.
    Damager and damage are currently unused. (It may be used by some entities to amplify the knockback)
    X and Z are the strengths of the knockback, as a 2D vector.
    Base is another amplifier for the knockback, but also contributes vertically.
    According to @shoghicp, the client ignores the knockback if it gets too strong.
    For reasonable parameters, see how the source code uses it: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Living.php#L169
     
  4. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    @SOFe I'm trying to change the direction where the knockback pushes to. I tried changing the x and z for the parameters but there's no difference.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.