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. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Well, you need to handle the direction in which the player is looking
     
  2. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
  3. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    wtf?
    if the player is looking north his right side is a different direction, so you can't just assume it's x +1
     
    xBeastMode and Jack Noordhuis like this.
  4. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You need to take into account that a player can turn around. This code only uses the position of a player, you need to use some trig to get a position that will always be right of the player.
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    I think something like this could do:
    PHP:
    public function spawnParticleAtRightSide(Player $player) {
      
    $radius 2// Set radius to 2
      
    $x sin(deg2rad($player->yaw 90) * $radius) + $player->x// Get yaw in degrees and add a quarter of 360 degrees to it and turn them to radians in order to use sin on it, multiply it with the radius and add it to the player X.
      
    $z cos(deg2rad($player->yaw 90) * $radius) + $player->z// Same counts for $z, but use cos here instead
      
    $player->getLevel()->addParticle(new FlameParticle(new Vector3($x$player->1$z))); // Add the particle on that location.
    }
    I haven't actually tried this code, but I think it works. Feel free to tell me if it doesn't.
     
  6. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Yeah I didn't think about this... I will come up with something new.
     
  7. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Change 90 to 180.
     
  8. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Use the direction vector.
     
  9. imYannic

    imYannic Baby Zombie

    Messages:
    113
    There is nothing which will turn it into the right side, this is exactly what I posted....
     
  10. #A6543

    #A6543 Zombie

    Messages:
    267
    It is already 180. But the particles are only 1 block from the player in the direction he looks
     
  11. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    The long post in this thread by @SOFe might help you understand what you need to do in order to achieve what you want.
     
    robske_110 (Tim) likes this.
  12. imYannic

    imYannic Baby Zombie

    Messages:
    113
    What if I told you that my code works?
    [​IMG]

    Code:
    PHP:
    $p $event->getPlayer();


    $yaw $p->yaw;
    $right $yaw 180;
    $x cos($right M_PI 180) * $p->x;
    $z sin($right M_PI 180) * $p->z;

    $p->getLevel()->addParticle(new FlameParticle(new Vector3($x$p->y$z)));
    * 2 is for your requested range of 2.
     
  13. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Yeah I tested yours (and mine) and they do work. I think you used it wrong in your code.
     
  14. #A6543

    #A6543 Zombie

    Messages:
    267
    That works! Is it possible to add particles from y+1 to y+5? Without adding every particle
     
  15. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    I don't know if this is the best way. But this could work:
    PHP:
    $arr = array(12345);
    foreach (
    $arr as $nr) {
    $level->addParticle(new FlameParticle(new Vector3($x$y+$nr$z)));
    }
     
    Sandertv likes this.
  16. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You can use a for loop.
    PHP:
    for ($i 1$i <= 5$i++) {
      
    $level->addParticle (new FlameParticle(new Vector3($x$y $i$z)));
    }
     
    VentroxStudio likes this.
  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.