WithThreeJS extension Particle emitter

Hi, guys. My question is about a way to implement any particle effects in WithThreeJS extension. There’s this screenshot on itch page of the extension’s creator :

After searching an information in google i was able to find out that it’s possible with javascript code. (because it’s impossible to add 3d behaviour for Particles object in gui) I’ve tried this :

runtimeScene.setBackgroundColor(100,100,240);

// First, create a new ParticleSystem object
var bloodParticles = new gdjs.evtTools.threejs.ParticleSystem();

// Set the properties of the particle system
bloodParticles.setTexture("Blood.png");
bloodParticles.setColor("0xff0000");
bloodParticles.setOpacity(1);
bloodParticles.setParticleCount(50);
bloodParticles.setParticleSize(1);
bloodParticles.setParticleSpeed(2);
bloodParticles.setParticleLifetime(2);

// Set the position of the particle system to the position of the enemy
bloodParticles.setPosition(Bird.getX(), Bird.getY(), Bird.getZ());

// Add the particle system to the game scene
gdjs.evtTools.threejs.addNewObjectToScene(runtimeScene, bloodParticles);

// Play the particle effect
bloodParticles.play();

// Wait for the particle effect to finish before removing it from the scene
setTimeout(function() {
    gdjs.evtTools.threejs.removeFromScene(runtimeScene, bloodParticles);
}, 2000);

But it doesn’t work at all. Debugger shoes nothing. So i’d be glad if someone explained any possible reasons why it doesnt work.

What’s the link to your source. I don’t don’t see any other code for the bird object. Is it referenced somewhere? Try your code with numbers instead of the bird reference to test the rest of the code.

Bird is the name of the object that exists in my object list. It’s just an example. I’ve tried with number as well. Doesn’t work anyway.

After this i’ve decided to test if JS code works in general. I’ve created a new project and did this :

I’ve tried like 10 variants of the code to change my global variable but it’s still 0 while the background becomes black that means that the first string works. So now i’m totally confused because even the simple code doesn’t work.

Ok. I wasn’t sure about bird. I know sometimes it needs an instance number like bird[0] but if numbers don’t work the that’s not the issue.

I use this for Global variables.

Get value of global variable:
-----------------------------
var globalVarNumber = runtimeScene.getGame().getVariables().get('globalVarName').getAsNumber();
var globalVarString = runtimeScene.getGame().getVariables().get('globalVarName').getAsString();

Set value of global variable:
--------------------------------
runtimeScene.getGame().getVariables().get('globalVarName').setNumber(100);
runtimeScene.getGame().getVariables().get('globalVarName').setString(“new text”);

I’ve been adding snippets to a cheat sheet. This might help. I’m not saying everything is correct but it all works for me.

doug13579/Gdevelop-JavaScript-Cheat-sheet: I’m not saying these are the best way or even reliable ways but they work for me. Use them or abuse them as you see fit. I offer no guarantees. (github.com)

1 Like

Your code works. So you don’t have any thoughts about why the code from the first post doesnt?

I can figure out JavaScript but this is beyond me. It looks like something is missing to tie it into Gdevelop. I wish you luck.