Physics ignores collisions in headless mode

Hello!

I’m trying to implement a simple 2d game with physics, based on 3d.
Now I wrote a model (which deals with bulletAppState and so on), server and client.

When I’m launching server with GUI everything works OK, but when I’m launching server in headless mode (SimpleApplication::start(JmeContext.Type.Headless) and don’t attach Nodes to GUI node), sometimes collisions of my ball (dynamic) and player (kinematic) doesn’t work – it acts like there is no player; meanwhile, walls (static) works fine.

What could be wrong?

P.S.: Here is my source code: GitHub - sn-ma/PoolGame . It’s on Kotlin, and I’m using maven to build it up.

I’m holding a piece of string, how long is it, and how can I make it dance when I play the flute? :smiley:

Try showing your code or some stackprint - then maybe, help will find its way towards you.

It seems that the bug isn’t reproduced when the nodes are attached to scene graph. But why?

Because of the stuff.

Should I add all the objects to the scene every time?

It’s because of that line right there. The one just above the other one.

1 Like

@asser_fahrenholz, @pspeed

i dont know when, but he/she added sourcecode of his project, i belive it was after your comments.

it would be easier to have small TestCase that show issue, but project dont look to be big tho.

Myself i need learn Kotlin later too :slight_smile:

For physics, it doesn’t matter if you attach the spatial to the scene or not. But if you aren’t going to attach it to the scene then why use a spatial at all? Just use the rigid body directly.

And if your answer is “Because I look at the spatial for this or that” then recognize that nothing about the spatial will be updated to match the physics object because the spatial isn’t in a scene and thus its controls/position/etc. aren’t updated every frame.

1 Like

Thanks for comments!

Probably, I don’t actually need to create those spatials in the headless server case; but it’s easier to create them always – the code is shared between client and server, such as analysis of collision detection and so on.

For now I’ve updated the code on github, so, if you want to reproduce the bug, you should change the code block in file Model.kt from

        guiNode.apply {
            attachChild(player)
            attachChild(enemy)
            attachChild(ball)
        }

To

    if (isGuiEnabled) {
        guiNode.apply {
            attachChild(player)
            attachChild(enemy)
            attachChild(ball)
        }
    }

What Paul says about spatials on the server is true, and whilst I’m not very proficient in kotlin i see you set and get transforms on the spatial, but when you add a physics control you must interact with the physics control transform - including reading them.

It could be that you have mixed code somewhere reading the spatial (scene graph) transform on the server as a result - which would be wrong if you didn’t add them to the scene graph on the server.