Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Direction player looks particle

Comments in 'Plugin Development' started by RoboDaim, Aug 21, 2016.

  1. RoboDaim
    Offline

    RoboDaim New Member

    Joined:
    Aug 17, 2016
    Posts:
    5
    Minecraft User:
    RoboDaim
    how to create a line of particles where the player is looking?
    PHP:
    for($min0;$min<40;$min++)
    {
    //spawning particle
    }
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:

    $x 
    $player->getDirectionVector()->
    $y 
    $player->getDirectionVector()->y;
    $z $player->getDirectionVector()->z;
    $px =  $player->x;
    $py $player->y;
    $pz $player->z;


    for(
    $i 0$i 40$i++){
    $level->addParticle(new FlameParticle(new Vector3($i $x $px$i $y $py$i $z $pz)));

    }

  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz


    IN PRACTICE:

    Steve has a Yaw of 90 and a Pitch of 0.
    Steve's coordinates are 100, 4, 100.

    $x will be 0;
    $y will be 0;
    $z will be 1.0;

    $px = 100;
    $py = 4;
    $pz = 100;

    Particlespawn1: 100, 0, 101
    Particlespawn2: 100, 0, 102
    And so on...

    Practice test 2:

    Steve has a Yaw of 135 and a Pitch of 45.
    Steve's coordinates are 100, 4, 100.

    $x will be -0.5;
    $y will be 0.5;
    $z will be 0.5;

    $px = 100;
    $py = 4;
    $pz = 100;

    Particlespawn1: 99.5 4.5 100.5
    Particlespawn2: 99 5 101
    And so on
    ---------------------------

    To understand how Player::getDirectionVector() works,
    It uses a cosinus, sinus formula which is used in most coordinates based 3D games to moves things to their direction. You can get the Vector by that code too:

    PHP:

    $yaw 
    $player->yaw;
    $pitch $player->pitch;

    $y $yaw 45 M_PI 180;
    $p $pitch M_PI 180 * -1;

    $v3 = new Vector3;

    $v3->cos($y) * cos($p);
    $v3->sin($p);
    $v3->sin($y) * cos($p);

    return 
    $v3;

  4. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    In practice, it is probably more effective to add the unit vector every time:

    PHP:
    function(Player $playerParticle $particle){
      
    $position $player;
      
    $unitVector $player->getDirectionVector();
      for(
    $i 0$i 40$i++){
        
    $position $position->add($unitVector);
        
    $particle->setComponents($position->x$position->y$position->z);
        
    $player->getLevel()->addParticle($particle);
      }
    }
    Last edited: Aug 25, 2016
  5. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    function(Player $playerParticle $particle){
      
    $position $player;
      
    $unitVector $player->getDirectionVector();
      for(
    $i 0$i 40$i++){
        
    $position $position->add($unitVector);
        
    $particle->setComponents($position->x$position->y$position->z);
        
    $player->getLevel()->addParticle($particle);
      }
    }
    iDirtPlayzMC likes this.
  6. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Thanks, but next time, it would be much better if you point out the typo directly rather than copying the code and correcting it, which it would be troublesome to compare what's changed.
  7. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    okey

Share This Page

Advertisement