Energy particles displacing solids.

  • ProtoBlast
    10th May 2015 Member 0 Permalink

    I scripted an energy element, NULL, which displaces DMND. The problem is that it doesn't only displace it, it also destroys some of the DMND particles.

     

    Here is the code.

    (The velocity and reaction functions were written because they may be useful for other elements I might write in the same file. This way I don't have to repeat some things too many times)

     

    My guess is that, under some circumstances, the fact NULL has nowhere to be reflected to doesn't only cause it to disappear, but also DMND particles somehow.

     

    Is there any way to fix this?

     

    Thank you for replying in advance.

     

    PS: I don't know exactly what the nt variable of the update function actually is. All I know is that checking wether it is higher than 0 or not reduces the fps drop the element causes, so it would be nice if someone told me what it is.

    Edited 2 times by ProtoBlast. Last: 10th May 2015
  • RCAProduction
    10th May 2015 Member 0 Permalink

    Does it actually delete the DMND or does it just stack particles? (2 DMND on top of each other)? Place a circle of however many DMND, and look at the part count. After using NULL, open the console and type !set type dmnd dmnd

     

    If the number returned is the same as the particle count at the start, but it looks like DMND is missing, you have stacking. If the number returned is lower, you have DMND being deleted.

     

    -RCAP

    Edited once by RCAProduction. Last: 10th May 2015
  • ProtoBlast
    10th May 2015 Member 0 Permalink

    That's what I did: After testing big quantities of NULL on DMND, it seemed that there was less DMND than the beginning, so I did it again and used !set life dmnd 0 to check part count before and after the NULL wave.

     

    The results confirmed that DMND particles actually disappear (DMND parts number got reduced).

    Edited 3 times by ProtoBlast. Last: 10th May 2015
  • ProtoBlast
    19th May 2015 Member 0 Permalink

    Bump, still waiting for answers.

  • jacob1
    19th May 2015 Developer 1 Permalink
    Whenever a particle changes type or is killed in an update function, it needs to return true to tell the game to stop simulating that particle because it is something else now. I suggest adding "return true" in the reaction function then returning that from the main update function. wiki link

    In the next version of the game, it will automatically detect that your particle changed type and this won't be necessary any more. For now, you still need to return true.


    The reason the DMND disappears is a bit weird. After NULL and DMND swap types, the game doesn't realize that the NULL is now DMND and continues simulating the DMND as an energy particle. If there is nowhere for the energy particle to move to, it gets killed. This is why simulation needs to be canceled if a particle changes types, the game (currently) won't check if something changed.
    Edited once by jacob1. Last: 19th May 2015
  • ProtoBlast
    19th May 2015 Member 0 Permalink

    @jacob1 (View Post)

     

    Thank you very much for replying.

     

    I'm currently having another problem: adding "return true" in the reaction function (inside or outside of the if_then structure) and in the main function causes NULL to not move.

     

    NULL particles still gain an initial velocity from the "velocity" function, but they don't move accordingly to their velocities; they don't move at all, yet they retain their velocity.

    Edited once by ProtoBlast. Last: 19th May 2015
  • jacksonmj
    19th May 2015 Developer 0 Permalink

    nt is the number of neighbouring positions (in a 1 pixel radius) which are either empty or contain a particle of a different type to the current particle.

     

    So if nt is 0, that means the current particle is stuck in the middle of a load of identical particles, so there won't be any DMND immediately next to it to react with.

    Edited 2 times by jacksonmj. Last: 19th May 2015
  • jacob1
    19th May 2015 Developer 0 Permalink
    only return true if the particle changes type (inside that "if" inside the reaction). If not, return false (returning nothing should have the same effect).

    returning true will cancel all the movement code, and should only be done if something has changed with the type.
  • ProtoBlast
    19th May 2015 Member 0 Permalink

    @jacksonmj (View Post)

     

    Thank you for answering my nt question.

     

    @jacob1 (View Post)

     

    That worked, thank you.

    Edited once by ProtoBlast. Last: 19th May 2015
  • jacob1
    19th May 2015 Developer 0 Permalink
    I did find a strange bug, it doesn't set velocity if there is a Newtonian Gravity field. Instead of setting velocity when vx or vy is 0, I recommend you set it when .tmp is 0. And then set .tmp to 1 so that only happens once.