Forcefully move player

Discussion in 'Development' started by minijaham, Apr 24, 2021.

  1. minijaham

    minijaham Zombie Pigman

    Messages:
    737
    GitHub:
    minijaham
    Hey! I've seen this animation(player moving) where when an ender pearl lands, it dashes the player to the location where the ender pearl landed.

    I've tried ProjectileHitBlockEvent with setMotion() but it didn't seem to work.

    My attempt:
    PHP:
    // ProjectileHitBlockEvent
    $projectile $event->getEntity();
    $owner $projectile->getOwningEntity();
    if(
    $projectile instanceof \pocketmine\entity\projectile\EnderPearl){
                if (
    $owner instanceof Player){
                    
    //$projectile->flagForDespawn();
                    //$coord = new Vector3($projectile->getX(), $projectile->getY(), $projectile->getZ());
                    //$owner->setMotion($owner->getMotion()->multiply(2.0));
                    //var_dump($owner->getMotion()->add(2.0));
                    
    $owner->setMotion($owner->getDirectionVector()->multiply(2.0));
                    
    var_dump($owner->getDirectionVector()->multiply(2.0));
                }
    What am I doing wrong, and if it is impossible with what I am currently doing, what else can I do?
     
  2. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    120
    Yea use a ProjectileHitBlockEvent but instead of getting the player to run to the landed pearl, maybe teleport the player to the pearl unless you want the player to dash into it.
     
  3. minijaham

    minijaham Zombie Pigman

    Messages:
    737
    GitHub:
    minijaham
    teleporting to the pearl is what it originally does. I want the player to dash(move) to the pearl on land
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    537
    To set the motion to go towards the pearl you can do
    PHP:
    $owner->setMotion($projectile->subtract($owner));
     
    minijaham likes this.
  5. minijaham

    minijaham Zombie Pigman

    Messages:
    737
    GitHub:
    minijaham
    Hmm, seems like that didn't do anything as well. What could I be doing wrong?
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    537
    Hmm it seems you have to cancel EntityTeleportEvent, or override Enderpearl's onHit() to prevent the teleport. Since teleporting resets the motion it might seem like it didn't have any effect
     
  7. minijaham

    minijaham Zombie Pigman

    Messages:
    737
    GitHub:
    minijaham
    Ah..I see. Thanks for the reply. I also think I found a way, but I can't get it as smooth as SynHCF's pearl system. I guess marshall(CortexPE) is really a mysterious guy...
     

Share This Page

  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.