Here is my code: PHP: $entity = (new class($p->getLevel(), new CompoundTag('', [ new ListTag("Pos", [ new DoubleTag("", ($args['pos'] ?? $p->asVector3())->getX()), new DoubleTag("", $p->getY()), new DoubleTag("", ($args['pos'] ?? $p->asVector3())->getZ()) ]), new ListTag("Motion", [ new DoubleTag("", 1.0), new DoubleTag("", 1.0), new DoubleTag("", 1.0) ]), new ListTag("Rotation", [ new FloatTag("", -90), new FloatTag("", -90) ]) ])) extends \pocketmine\entity\Entity { public $width = 1; public $height = 2;});$entity->teleport(new \pocketmine\level\Location(($args['pos'] ?? $p->asVector3())->getX(), $p->getY(), ($args['pos'] ?? $p->asVector3())->getZ(), -90, -90, $p->getLevel()));$p->knockBack($entity, 0, ($args['pos'] ?? $p->asVector3())->getX(), ($args['pos'] ?? $p->asVector3())->getZ(), $args['knockback'] ?? 1);$entity->close(); I even tried to set the entity's rotation to other values but still not work
1) What do you want to do with that code? 2) You needn't create new entity, you can use player you are knockbacking PHP: $p->knockBack($p, 0, $x, $z, 0.4 * 2); // 2x higher knockback
Oof, it is still not working. I keep getting knocked to the right side instead of the centre as the video shown, is there a solution for that?
You could knock the player really high in the air and then teleport them to the spawn point above the clouds, so they cant see theyve been teleported. and then make them fall to the spawn. it will create the illusion that theyve been knocked back to spawn, but idk if thats what ur going for. just a suggestion
Here is simple code you can use, maybe it will need change some constants, but it worked fine when I tested it. PHP: /** @var Player $player */$spawn = $player->getLevel()->getSpawnLocation();$maxKnockBack = 5;$motion = $spawn->subtract($player);if(abs($motion->getX()) > $maxKnockBack) { $motion->x = ($motion->getX() <=> 0) * $maxKnockBack;}if(abs($motion->getZ()) > $maxKnockBack) { $motion->z = ($motion->getZ() <=> 0) * $maxKnockBack;}$dist = (new Vector2($player->getX(), $player->getZ()))->distance($spawn->getX(), $spawn->getZ());$player->knockBack($player, 0, $motion->getX(), $motion->getZ(), min((mt_rand(10, 15) / 10), $dist / 10));