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

How to move particle to back from Player(as much as 0.5)

Discussion in 'Development' started by Hoyee, Feb 22, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    I made Particle with trigonometic functions, but I don't know how to move it back from player. How can I move it as much as 0.5 back?
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    [​IMG]

    The angle can be replaced with Player->getDirection(). And smaller radius you get if you divide both functions by the number...

    For example:

    Code:
    x = 1/2 * cos(angle)
    z = 1/2 * sin(angle)
    
    If the particle is displayed at player's front then just add PI to the angle to move it to player's back...
     
    HimbeersaftLP likes this.
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    I don't think that helped me. here is some code, can you edit it for what I wonder?

    for ($i = 0; $i <= 1; $i=$i+0.2) {
    $yaw = $p->yaw;
    $right = $yaw + 180;
    $x = cos($right * M_PI / 180) * $i + $p->x;
    $z = sin($right * M_PI / 180) * $i + $p->z;
    $p->getLevel()->addParticle(new FlameParticle(new Vector3($x, $p->y+1, $z)));
    }

    I want to make it move back as much as -0.5 On the basis of Player.
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I'm sorry, I didn't write it right. Use Player->getYaw() insteadof Player->getDirection();
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Btw you want to add more particles, or just one?
     
  6. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Sorry I see it late, I meen like wings? when I make particle, it just created in player's body(?) so I want to move particle to player's back.

    I tried many time but it doesn't create that I wanted
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    So there is code I'm using... If you don't understand it, just use some plugin for that, I don't think it's good to use that without understanding the problematics.

    Here is base of the code...
    Code:
    x = cos yaw + dist * sin yaw
    z = sin yaw - dist * cos yaw
    
    Then you can create more expanded code from that:
    PHP:
       /**
         * @param $radius
         * @param $angle (Angle in degrees -> player's yaw)
         * @param int $size (Count of generated particles)
         * @param int $stacking (Particles / 1 block)
         *
         * @return \Generator [$x, $z]
         */
        
    public function generateTangentForCircle($radius$angleint $size 1$stacking 10): \Generator {
            
    $angle deg2rad($angle) - M_PI_2// pi/2

            
    $particlesCount = (int) ceil(abs($stacking) / 2);

            for(
    $i = -$particlesCount$i <= $particlesCount$i++) {
                
    $x = ($radius cos($angle)) + ($i $particlesCount $size sin($angle));
                
    $z = ($radius sin($angle)) - ($i $particlesCount $size cos($angle));

                yield [
    $x$z];
            }
        }
     
  8. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    This code is just for generating line at player's back. Next particles you will have to generate with changing Y axis
     
  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.