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

pushback players

Discussion in 'Development' started by Levi, Jun 17, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    how do i push players back like lbsg when you get too close to the gamemodes

    i tried knockback($Player,0,0.5,0.5,1) it dont push me back it push somewhere else
     
  2. Heisenborger

    Heisenborger Spider

    Messages:
    9
    You need a point from where you want the player to be pushed away.

    In this case it seems like you need this point to be in front of the player.

    You can achieve this by doing the following:

    PHP:
    // $p is the Player object

    $point $p->getDirectionVector()->add($p);// This is a Vector3 even if only X and Z are needed
    $force 0.5;// Or whatever force you like
    $p->knockBack($p0, ($p->$point->x), ($p->$point->z), $force);

    //In this case can also be done like that:

    $direction $p->getDirectionVector()->multiply(-1);// This is a Vector3 even if only X and Z are needed
    $force 0.5;// Or whatever force you like
    $p->knockBack($p0$direction->x$direction->z$force);
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i want them to be pushed back not in front
     
  4. Heisenborger

    Heisenborger Spider

    Messages:
    9
    That's what I've actually done. I think you misunderstood.
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Why doesn't try setMotion?:
    PHP:
    $player->setMotion(new Vector3(-1.500));
    this should be work.
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
     
  7. Heisenborger

    Heisenborger Spider

    Messages:
    9
    You forgot to read the first part: You need a point from where you want the player to be pushed away.

    If you push away the player from a point in front of himself it actually will be pushed backwards
     
  8. Heisenborger

    Heisenborger Spider

    Messages:
    9
    There is no way this will push the player backwards
     
  9. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    This will be work, did you try it?
     
  10. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    it doesnt it only it push back player to the right and its not smooth
     
  11. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    I use this:
    PHP:
    $player->setMotion(new Vector3(-1.510));
    it push you back with a little jump.
     
  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.