Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravity behaves oddly when emitter not at origin #9

Open
richardTingle opened this issue Dec 21, 2021 · 1 comment
Open

Gravity behaves oddly when emitter not at origin #9

richardTingle opened this issue Dec 21, 2021 · 1 comment

Comments

@richardTingle
Copy link
Contributor

I've encounter an issue where if the emitter is set to ParticlesFollowEmitter (The default) and the emitter isn't at the origin then gravity behaves oddly

image

Example application

public class TestMain extends SimpleApplication{

    public static void main(String[] args){
        TestMain app = new TestMain();
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");

        Texture tex = assetManager.loadTexture("Effects/Particles/part_light.png");
        mat.setTexture("Texture", tex);
        Emitter emitter = new Emitter("mushroomParticles", mat, 200);
        emitter.setParticlesFollowEmitter();
        emitter.setStartSpeed(new ValueType(0.0f));
        emitter.setLifeFixedDuration(1.5f);
        emitter.setStartSize(new ValueType(0.02f));
        emitter.setEmissionsPerSecond( 10);
        emitter.setParticlesPerEmission(1);
        emitter.setShape(new EmitterCone());
        ((EmitterCone)emitter.getShape()).setRadius(0.1f);
        emitter.addInfluencer(new GravityInfluencer(new Vector3f(0,2,0)));
        emitter.setLocalTranslation(5, 0, 0);

        rootNode.attachChild(emitter);
        cam.setLocation(new Vector3f(0, 0, 1.5f));
        cam.lookAt(new Vector3f(5,0,0), Vector3f.UNIT_Y);
    }
}

Looking at the source of gravity influencer

@Override
public void update(ParticleData p, float tpf) {
	if (enabled) {
		gravity.getValue3f(p.percentLife, p.randomValue, store);

		// transform so the gravity applies according to the world
		if (emitter.getParticlesFollowEmitter()) {
			emitter.getWorldTransform().transformVector(store, store);
		}
		p.velocity.x -= store.x * tpf;
		p.velocity.y -= store.y * tpf;
		p.velocity.z -= store.z * tpf;
	}
}

It seems like the influencer is trying to ensure that gravity still points down even if the emitter is rotated? But my understanding is that that isn't what ParticlesFollowEmitter means, that ParticlesFollowEmitter means if the emitter moves all its ALREADY emitted particles move as well?

I'm not sure I understand this one enough to make a change, for myself I'm just going to create my own GravityInfluencer that doesn't have this behaviour but I wanted to draw attention to it

@Jeddic
Copy link
Owner

Jeddic commented Dec 21, 2021

Just checked this, and I think you are right. Gravity force should only really change with the rotation. I've changed it with my local copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants