Hello jme-community,
I have an problem with the collision detection and I hope that someone on here can help me.
What worked so far: I have a loaded Map, and Player(s). Collision detection function as expected. Player(s) doesn’t fall or glitches through map - nice.
The Problem: My latest features adds items to the game. The Player can run against them, the Item will stop the player (item has a mass of 0), so I suspect the collision is working, But my CollisionListener doesn’t receive any collision events for this.
My expections: I added the items exactly the way I added the player. Player, Level and Item have both the same collision-group. The collision can be experienced by the player. I expected to now have the collision-events for player and map, and also for player and item. But that isn’t the case.
Currently I’m really not sure what’s wrong. I have an other Project with older jme-version and BulletAppState where something similar works, but didn’t find any differences in the game-code nor jme-code. I tried to find similar problems in the community but didn’t found any. I highly suspect that I’m missing something configuration or method-invocation-wise, but cannot find anything in jme-code. So I’m asking you for help.
Cheers
qriz
The Code (kotlin):
(jme3-3.2.1-stable with jme3-bullet-native, caution I do not use BulletAppState)
How the level is added to PhysicsSpace:
val levelNode = assetManager.loadModel(levelName) as Node // (level is j3o-file)
val levelShape = CollisionShapeFactory.createMeshShape(levelNode)
val levelControl = RigidBodyControl(levelShape, 0f)
levelControl.userObject = GameObject.INVALID_ID //kotlin invokes setUserObject
physicSpace.add(loadedLevel.physicLevel)
How the player is added to PhysicsSpace:
val playerShape = SphereCollisionShape(1f)
val playerControl = RigidBodyControl(playerShape, 0.1f)
playerControl.userObject = playerId
physicSpace.add(playerControl)
The player position is updated before each bullet invocation:
playerControl.physicsLocation = (player.playerState.position) //kotlin invokes setPhysicsLocation
playerControl.physicsRotation = Quaternion.IDENTITY
How the item is added to PhysicsSpace:
val itemShape = SphereCollisionShape(0.5f)
val itemControl = RigidBodyControl(itemShape, 0f)
itemControl.userObject = itemId
itemControl.physicsLocation = state.position
itemControl.physicsRotation = Quaternion.IDENTITY
physicSpace.add(itemControl)
How PhysicsSpace is invoked:
physicSpace.update(delta.toFloat() / 1000f)
physicSpace.distributeEvents()
How PhysicsCollisionListener is added:
physicSpace.addCollisionListener(this)