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

addParticle

Discussion in 'Development' started by #A6543, Jan 4, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    I tried to set particles to the right site of a player. But if he moves the particles aren't moving with the player.

    My code:
    PHP:

    $level 
    $player->getLevel();
                
    $x $player->x;
                
    $y $player->y;
                
    $z $player->z;
    $level->addParticle(new FlameParticle(new Vector3($x$y+1$z+1)));
     
  2. Ozelord

    Ozelord Spider

    Messages:
    8
    Do you use the PlayerMoveEvent? :shoghi:
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    No. RepeatingTask
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    show full class code with scheduling code please
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    PHP:
    class GameSender extends PluginTask {

        public 
    $prefix "";

        public function 
    __construct($plugin) {
            
    $this->plugin $plugin;
            
    $this->prefix $this->plugin->prefix;
            
    parent::__construct($plugin);
        }

        public function 
    onRun($tick) {
            
            foreach (
    $this->plugin->getServer()->getOnlinePlayers() as $player)
            {
    $level $player->getLevel();
                
    $x $player->x;
                
    $y $player->y;
                
    $z $player->z;
                
    $name $player->getName();
    $level->addParticle(new FlameParticle(new Vector3($x$y+1$z+1)));
                    
                }
            }
    }
     
  6. Ozelord

    Ozelord Spider

    Messages:
    8
    Do you get any errors in the console? And are you sure that the task runs?
     
    Last edited: Jan 4, 2017
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    The task runs. The I can see the particles. Did u read my question???

    If I use $player->z; and the player turns around the particles aren't anymore at the players right side
     
  8. Ozelord

    Ozelord Spider

    Messages:
    8
    Oh sorry.. ._. Yeah thought the particles doesent spawn..
     
  9. #A6543

    #A6543 Zombie

    Messages:
    267
    Do u know how I can get the right side of a player?
     
  10. imYannic

    imYannic Baby Zombie

    Messages:
    113
    You need some math for that.
    PHP:
    $yaw $player->yaw;
    $right $yaw 180;
    $x cos($right M_PI 180) + $player->x;
    $z sin($right M_PI 180) + $player->z;
    $y $player->1;
    Test it, tell me if if it works.
     
    Last edited: Jan 5, 2017
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    It doesn't work
     
  12. #A6543

    #A6543 Zombie

    Messages:
    267
    Does someone know how to do that??
     
  13. imYannic

    imYannic Baby Zombie

    Messages:
    113
    I fixed it, try it now
     
  14. #A6543

    #A6543 Zombie

    Messages:
    267
    That makes the particles only moving in the direction the players looks
     
  15. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    The particle doesn't show when the player moves only when the task runs. So if you want it to move with the player use \pocketmine\event\player\PlayerMoveEvent.

    WARNING: this may cause lag to your server.
     
  16. #A6543

    #A6543 Zombie

    Messages:
    267
    ... I know how to do that. Pls read my question...

    I want to add particles to the right side of a player..
     
  17. #A6543

    #A6543 Zombie

    Messages:
    267
    With this code the particles will spawn there where the player is looking at. But they don't rotate
     
  18. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Well, you didn't specify how many blocks to the right you want the particles to show.
     
    Emre Bozkurt likes this.
  19. #A6543

    #A6543 Zombie

    Messages:
    267
    That's not important. But if you want a number. Two blocks from the players right side
     
  20. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Yes, it's important. Every small detail is important to future developers who might want to do the same.

    Anyways this might help:
    PHP:
    //Note: this only spawns a small particle at once two blocks to the right side of a player
    //Again, you did not specify the physical shape that you want the particle to have

    $blocks2right 2;//blocks you want it to go to the right.

    $pos = clone $player->getPosition();
    $pos->+= $blocks2right;
    $pos->level->addParticle(new FlamingParticle($pos));
     
  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.