First of all,my English is poor,may I can express my question correctly. I want to develope a plugin that can: When player press right button,he move left. When player press left button,he move right. When player press up button,he move back. Can Pocketmine make this idea come true? Which function should I use? Thank you very much!
You need to capture the onPlayerMove event and in there do: PHP: $to = $event->getTo();$from = $event->getFrom();$dx = $to->getX() - $from->getX();$dy = $to->getY() - $from->getY();$dz = $to->getZ() - $from->getZ();$to->setComponents($from->getX() - $dx, $to->getY(), $from-getZ() - $dz);// You should check collisions here!$event->setTo($to);
Thank you for your reply,but it didn't work. PHP: <?phpnamespace mine\ChaosDirection;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\Server;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\math\Vector3;use pocketmine\Player;class main extends PluginBase implements Listener { public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this,$this); } public function onPlayerMove(PlayerMoveEvent $event){ echo '1'; $to = $event->getTo(); $from = $event->getFrom(); $dx = $to->x - $from->x; $dy = $to->getY() - $from->getY(); $dz = $to->getZ() - $from->getZ(); $to->setComponents($from->getX() - $dx, $to->getY(), $from->getZ() - $dz); $event->setTo($to); } } [/QUOTE]
Yes, forgot... Change the : PHP: $to = $event->getTo(); to PHP: $to = clone $event->getTo(); However, you still need to check for collisions... i.e. if there is a wall where you are heading to, it will glitch into it.
It won't be fluent anyway. Motions are first handled in MCPE then PocketMine. In that way it is only possible to teleport/boost the player to the opposite direction, which has terrible visual performance. Also, you should handle EntityMotionEvent rather than PlayerMoveEvent.
It worked!But just as the Floor 4 said,it had a terrible visual performance.Anyway,thank you very much!
YES,the event happened first in the Minecraft ,then the event would be passed to PocketMine.The delay give the player a bad experience.