[SOLVED] Fireball attack implementation

Hello dear community,

I made a nice fireball particle effect. The player shall be able to throw these fireballs. The fireball shall “fly” into the direction the player is looking at in a straight line. Furthermore, the fireball can hit other players but it also can collide with the terrain etc.

The thing is I am not sure how I should implement this. Has somebody done something similar like this already?

My first thought would be to create a sphere collision shape and make it static to be not affected by gravity and then move it every frame. Then I also could easily check for collision, right?

Best regards

I am doing it exactly like this, or comparable.
I have a model for the core I think (which is currently a tin can :smiley: ) and for this I have a custom collision listener which makes the fireball explode if it collides.

But don’t make it static, just set it’s impulse and wait for collision feedback.

I was looking in the wiki about collisions since I figured that there must be something specifically used for bullets and the like. This seems to be more or less what you’re looking for no? https://jmonkeyengine.github.io/wiki/jme3/advanced/collision_and_intersection.html#toolbar

Rather this

Oh! Yes use this. Not what I posted. Sorry.

This one even has a small list saying that you shouldn’t use what I posted for what you’re doing. My bad.

Alright, thanks for your quik answers.

Could you please tell me how I should setup the physics control then? If I don’t make it static (mass = 0) it will be affected by gravity, right?

Unless you remove its gravity.

1 Like

Hello pspeed, sorry if this sounds stupid or anything but I could not find a way to “remove” the gravity of a single physics object such as my firball. Setting the gravity to (0,0,0) does not have any effect. I also could not find anything in the wiki, sorry. Could you please help me one more time?

So without looking at your code I had a similar issue with this. [Solved] Class that extends RigidBodyControl and gravity issues - #6 by thecyberbob

Essentially I had set it how I thought I needed to but the objects kept falling through the floor.

1 Like

Did you set the gravity before or after you added it to the physics space and it applied the default gravity?


RigidBodyControl.setGravity(new Vector3f(0f,0f,0f));
See: [https://jmonkeyengine.github.io/wiki/jme3/advanced/physics.html#specify-physical-properties]

1 Like

Ok, maybe this helps. Here is the code

package de.gamedevbaden.crucified.tests;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import de.gamedevbaden.crucified.enums.Scene;

public class FireballTest extends SimpleApplication {

    public static void main(String[] args) {
        new FireballTest().start();

    public void simpleInitApp() {
        BulletAppState bulletAppState = new BulletAppState();


        bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0,-9.81f, 0));
        Spatial scene = assetManager.loadModel(Scene.GameLogicTestScene.getScenePath());
        RigidBodyControl scenePhysicsControl = new RigidBodyControl(CollisionShapeFactory.createMeshShape(scene), 0);

        AmbientLight light = new AmbientLight();

        inputManager.addMapping("FIRE", new KeyTrigger(KeyInput.KEY_SPACE));
        inputManager.addListener(new ActionListener() {
            public void onAction(String name, boolean isPressed, float tpf) {
                if (!isPressed)return;

                Spatial fireball = assetManager.loadModel("Models/Effects/Fireball.j3o");

                RigidBodyControl fireControl = new RigidBodyControl(CollisionShapeFactory.createBoxShape(fireball), 1);
                fireControl.setGravity(new Vector3f(0,0,0));

                FireballCollisionListener listener = new FireballCollisionListener(fireControl);

        }, "FIRE");


    private class FireballCollisionListener implements PhysicsCollisionListener {

        private RigidBodyControl fire;

        private FireballCollisionListener(RigidBodyControl fire) {
            this.fire = fire;

        public void collision(PhysicsCollisionEvent event) {
            if (event.getObjectA() == fire || event.getObjectB() == fire) {

Alright, yeah, my mistake. I have to swap those two lines here

fireControl.setGravity(new Vector3f(0,0,0));


fireControl.setGravity(new Vector3f(0,0,0));

Thank you all for the great help!


Hint to future readers:
This is because adding an object to a physics space sets it’s gravity to the space’s gravity.