GhostControls not colliding

Greetings! I just got started with JME3 today, and while I’ve tried to give everything a good thorough read-through, I might have missed something obvious. If that’s the case, sorry for the redundant thread.



Anyways, in order to learn more about JME3, I decided to make a little game (what better way to learn about making games!?). I didn’t want to make a complicated game, so I decided to try and make a simple game of Pong. I made 2 paddles and a ball. I got user input setup. I got the ball moving and bouncing off the top and bottom of the screen, and I have the opponents paddle moving right along with it.



The next thing was obviously to check for collisions against the paddles. For that, I decided to give Bullet a shot (I thought there were probably internal methods that would do just as well in this case, but it’s a learning experience, also, no pun intended). I created a GhostControl for all three objects, add the controls to the physics space, and setup a physics listener.



The problem is that the ball only seems to collide with the opponents paddle. I watch the console for output and see the “Static-static collision” message when those two collide, but nothing happens when the ball collides with the players paddle.



Here are some relevant snippets from my code:



Creating the Player

[java]

Box b = new Box(new Vector3f(0,0,0), .1f,0.6f,0.5f);

Geometry one = new Geometry(“one”, b);

one.setMaterial(mat);

player = new Node(“Player”);

player.attachChild(one);

[/java]



Player Physics

[java]

CollisionShape playerShape = CollisionShapeFactory.createBoxShape(player);

control_playerPaddle = new GhostControl(playerShape);

player.addControl(control_playerPaddle);

[/java]





The code for the Opponent Paddle is just the same, albeit with different variable names. And for the Ball, it’s also the same, but with a Sphere shape. They all use GhostControls.



Adding to Physics Space

[java]

bulletState.getPhysicsSpace().add(control_opponentPaddle);

bulletState.getPhysicsSpace().add(control_playerPaddle);

bulletState.getPhysicsSpace().add(control_ball);

[/java]



Adding PhysicsListener

[java]

bulletState.getPhysicsSpace().addCollisionListener(physicsListener);

[/java]



I then have a PhysicsCollisionListener (called physicsListener) that I know is working because it detects the collisions between opponent paddle and the ball. I imagine it must be something to do with either creating the collision shape for the player paddle, or perhaps keeping it in sync with the player paddle when it’s moving.



Any ideas? Thanks guys!

Ther is not “this kind” of collisions with ghost objects, thats their main point. If there was then stuff would bounce off of them. You can get the overlapping objects of ghost objects. Via the corresponding method.

@normen said:
Ther is not "this kind" of collisions with ghost objects, thats their main point. If there was then stuff would bounce off of them. You can get the overlapping objects of ghost objects. Via the corresponding method.


Sorry, could you clarify that a little bit. I thought the purpose of the GhostControl was essentially to act as a bounding volume that is managed by the BulletState. I assumed, then, that when two GhostControls overlapped, it would register as an Event in the "PhysicsListener." Indeed, I have included code in the "PhysicsListener" to allow the ball to bounce off of the paddles and that seems to be working for one of the paddles, but it is completely ignored for the other.

I'll give it a shot with getOverlapping, but if you wouldn't mind, would you explain to me why the PhysicsListener is partially working?

Thank you

Are you sure its actually the paddle causing the collision event? At any instance, use kinematic bodies and not ghost controls.

I figured out what the problem was.



This:

[java]

CollisionShape playerShape = CollisionShapeFactory.createBoxShape(player);

[/java]

wasn’t working. I enabled physics debug display and nothing showed up. Of course, it’s the first time I ever used it, so I wasn’t sure exactly what I was supposed to see, but I figured it would show bounding boxes, or something. Anyways, I replaced that line with:



[java]

CollisionShape opponentShape = new BoxCollisionShape(new Vector3f(0.1f, 0.6f, 0.5f));

[/java]



and the debug data showed up. So I replaced the other two CollisionShapes with similar code, and now it’s working.



Now that I’ve got it working, I might as well give the Kinematic Bodies a try. This little game is only meant as a learning experience anyways!



Thanks again!