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

Particles

Discussion in 'Development' started by LucGamesDE, Apr 3, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I make Particles randomly fly around a player?
     
  2. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    My idea is to use RepeatingTask, set it around 3 ticks is optimal. On every tick, spawn a new particle around Player, and saves the last particle spawn coordinate for next particle. I think this can achieve that "fly" animation.
     
  3. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    I want to make random circle particles. (I know how to add particles and so on)
     
  4. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    PHP:
    $r 1//Radius, the distance of the particle and the player
    $diff 30//The smaller, the smoother the transition effect
    for($theta 0$theta <= 360$theta += $diff){
        
    $x $r sin($theta);
        
    $z $r cos($theta);
        
    //Add up player x, z with above $x, $z and spawn the particle
    }
    This is the code for Circular Coordinate Calculation. In every for loop, new $x diff anf $z diff is calculated, just add the diff x and z with Player's x, z and it should be working fine. I think this is the one you looking for ;)

    EDIT: This is the basic one 2d Circle Calculation, remember to lift up Player's Y to show it around player. And I havent test this code, but the concept of that code is correct
     
    Last edited: Apr 3, 2017
    MagicLJ, Muqsit, Primus and 1 other person like this.
  5. hoyinm14mc

    hoyinm14mc Silverfish

    Messages:
    22
    Wow the Math looks simpler:D
     
    Primus likes this.
  6. hoyinm14mc

    hoyinm14mc Silverfish

    Messages:
    22
    Oh but wait.. Your code has problem. In Sine and Cosine, 30° is actually no difference with 150° as sin(30) an sin(150) are both 1/2, so when $theta in the for loop is the (value <= 90)+180 then those X positions would be same.
     
  7. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    You forgot to think of Z ;)

    When theta = 30,
    diffX = sin(30) = 0.5
    diffZ =cos(30) = 0.866

    When theta = 150,
    diffX = sin(150) = 0.5
    diffZ = cos(150) = -0.866 <- negative

    Hence, the position won't be the same. In a circle loop, its possible to get same value of each x and z for more than twice. Check the cosine and sine graph and you will know it ;)

    Math xD
     
    jasonwynn10 and MagicLJ like this.
  8. hoyinm14mc

    hoyinm14mc Silverfish

    Messages:
    22
    Oh forgot the cosine property xdd
     
  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.