Thank you Mark.
I’m looking at doing something with moving rocks but I did’t see how to clean up things.
What would be the best way to track how many pooled objects I have. (for debugging)?
Thanks for all your help!
Steve
Thank you Mark.
I’m looking at doing something with moving rocks but I did’t see how to clean up things.
What would be the best way to track how many pooled objects I have. (for debugging)?
Thanks for all your help!
Steve
Hi Steve,
Once constructed there’s no way at the moment for “deleting” the memory used so it’s not possible to do the traditional clean up of removing objects.
The best thing to do is create an array of the objects like we do in the example above with the particles[]
array. You can use the .length property of the array to tell how many objects you have.
Thanks,
Mark
Thank you!
I was playing with the Particles code and found it had colored one. So I added your code and a random color code to it:
Steve
var no_particles = 15;
var d = 1;
var particles = [];//create the particles and push them to the group
var plusOrMinus = function(){
if(Math.random() > 0.5){
return 1;
}
else{return -1;}
};// Color pick send color number 0-4 if more then 3 change
var color = function(){
var c = 0;
c = Math.floor(Math.random() * 11);while (c > 5) { c = Math.floor(Math.random() * 11); }; return c;
};
for(var i = 0; i < no_particles; i++){
// create the particle and push it into the array
particles.push(Z.Symbol(“Glitter Particle”));
// then push that particle to the ‘particles’ group
symbol.nodes.particles.push(particles[i]);
}
export function activate(){
for(var i = 0; i < no_particles; i++){
// pass random parameters to that particle
var x = (Math.random() * d) * plusOrMinus();
var y = (Math.random() * d) * plusOrMinus();
var z = (Math.random() * d) * plusOrMinus();
var scale = Math.random() * 0.4 + 0.4;
var speed = 1 + 0.5 * Math.random();particles[i].nodes.code.set_x(x);
particles[i].nodes.code.set_y(y);
particles[i].nodes.code.set_z(z);
particles[i].nodes.code.set_scale(scale);
particles[i].nodes.code.set_speed(speed);
particles[i].nodes.code.set_color(color());}
for(var i = 0; i < particles.length; i++){
particles[i].nodes.code.activate();
}
};
This is -almost- exactly what I’m trying to do, and I’ve been diving into it to find out how to change it to suit my needs.
What I’d like to do is instead of having the particles radially move outward from their random position a random distance away from 0,0, but in the same plane, I’d like them to move -up- (perpendicular from the plane). I can’t seem to find this in the code, the speed is how fast it goes, not in which direction, so I figure this is ‘hardcoded’ within the Glitter Particle.
I can’t find how to change it though. Can you give me some pointers?
Hi Mark,
In the ‘particleCode’ script node within the zpp you should see three variables: x
, y
and z
.
These variables are currently being assigned a randomised value through the Math.random()
function, and then being passed in to the set_x
, set_y
, and set_z
functions (exported from the ‘Glitter Particle’ subsymbol) later on in the script.
By changing these values, you can change the direction that the particles will be travelling towards.
Hope this helps.
All the best,
Seb
Thanks, Seb!
I assumed those were the starting points of the particle. I Should be able to figure it out now
I have tried my own particles system, “water” style…
Very cool!
Here it’s the zpp file for those who want to play with it. Code similar from Mark’s, but the nodes are managed with JS objects. Everything is inside the node “code”. Enjoy!
Particles.zpp (370.4 KB)
Many thanks!
Cheers!
This is great, thanks for sharing! Are you looking to use this is a project soon? Love to hear a little more about what your plans are
Glad you like it!
Yes I’m using this kind of code for a small game I’m working on - nothing serious, just a way to learn more about Studio. In fact, I’m starting to consider Studio as a kind of IDE pour AR/VR JS application!
Hi Mark,
I have limited experience with coding- could you modify this code so that instead of activating when the box is pressed, the code will attach to an imported fbx object ( that has an attached animation) and will activate when the fbx object is pressed?
What your asking for is more or less the same thing. You have to use a button on any models. the model it’s self does not have a clicked on event. Place the button inside your model and change it to not visible.
Steve
@stevesanerd thank you! I have another question: If I wanted to replace the glitter.png file with one of my own and then get it into the hierachy as a glitter texture- how would I do that? right now, I have my own tex file called cytokine.png and when I drag it into the hierachy it has the ‘cube’ icon next to it rather than the ‘picture’ icon next to it like the texture:glitter:1 file shown. I have attached a screenshot to better demonstrate what I mean. Any guidance would be super helpful! Thank you!
I am also using this particle project https://zapworksforumuploads.s3-eu-west-1.amazonaws.com/original/2X/3/3405df4990849e164566d37af05f64a12e529803.zpp just for your reference.
Thank you!
Sorry i’m new to this, is it possible for the particle to be activated in a certain time using the timeline?
Yep. I would use a label in the time line and then you need to use the code from the Tracking_image-seen0 and notseen0
Then turn them off in there scrip
Steve
Hi Steve! Thank you so much for your response!
is it possible to elaborate more on the process to achieve this?