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

knockback

Discussion in 'Development' started by SavionLegendZzz, Mar 5, 2019.

  1. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Okay so i am trying to knockback a player once they reach the border (knock them backwards by the way) i know i can use Living::knockBack() but when i use it(my code):
    PHP:
     $player->knockBack($player0$player->getX() - $player->getX(), $player->getZ() - $player->getZ(), 0.4);
    nothing happens it even sends the message about the player hitting the border too(full code):
    PHP:
    if($this->getUtils()->getGameManager()->getStatus() === GameManager::STARTED_GRACE or $this->getUtils()->getGameManager()->getStatus() === GameManager::STARTED_PVP){
                    if(
    round($player->distance($player->getLevel()->getSpawnLocation())) >= Utils::$world->getBorder()){
                        
    $player->knockBack($player0$player->getX() - $player->getX(), $player->getZ() - $player->getZ(), 0.4);
                        
    $source = new EntityDamageEvent($playerEntityDamageEvent::CAUSE_CUSTOM0.1);
                        
    $player->attack($source);
                        
    $player->sendMessage(TextFormat::RED."You hit the RED ZONE");
                    }
         }
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    because $player->getX() - $player->getX() is 0 and $player->getZ() - $player->getZ() is 0, so no motion is proceeded
     
  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.