Skip to content

Gravity behaves oddly when emitter not at origin #9

@richardTingle

Description

@richardTingle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions