player speed

Discussion in 'Development' started by kaliiks, Feb 23, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    How i check how fast is player moveing?
     
    Last edited: Feb 23, 2017
  2. asyven

    asyven Spider

    Messages:
    14
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Skullex and Muqsit like this.
  4. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    i think you can check it with this lines: (not tested)

    PHP:
    public function onMove(PlayerMoveEvent $event){
        
    $from $event->getFrom();
        
    $to $event->getTo();
        
    $speed $from->distance($to);
       
        
    //now you can do whatever you like with $speed
        //if this doesnt work, then make a delay with 20 ticks and check the distance from the position before and after 20 ticks ^^
    }
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    What if the player teleports?
     
  6. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    hmm i forgot it :p
     
  7. kaliiks

    kaliiks Zombie

    Messages:
    250
    It tried to use
    It say Your speed is 0.191901901919blabla when i running really fast it say your speed is 1.9292902902290blabla i used if($speed >= 1){
    send message but dont say anything
    public function onMov11CCe(PlayerMoveEvent $event){
    $from = $event->getFrom();
    $to = $event->getTo();
    $speed = $from->distance($to);
    $event->getPlayer()->sendMessage("Your speed is $speed");
    //if this doesnt work, then make a delay with 20 ticks and check the distance from the position before and after 20 ticks ^^
    if($speed >= 1){
    $event->getPlayer()->sendMessage("Your speed");
    }
    }
     
  8. kaliiks

    kaliiks Zombie

    Messages:
    250
    Ah, it was working sorry:-D
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Speed is distance/time, not final distance - initial distance. This might still be close.
     
    Skullex likes this.
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  11. madhon

    madhon Creeper

    Messages:
    2
    GitHub:
    mad-hon
    I'm curious why no one has answered this yet:
    PHP:
    $motion $player->getMotion();
    $speed sqrt(pow($motion->getX(),2) + pow($motion->getY(),2) + pow($motion->getZ(),2));
    Is that wrong?
     
  12. minijaham

    minijaham Skeleton

    Messages:
    800
    GitHub:
    minijaham
    This thread is literally from FOUR YEARS AGO
    And you can simply have a check for the speed attribute and make it to a value you want it to be shown, instead of having to get motion.
     
    NTT likes this.

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.