Overlaping

Hello world!



Beginner question here. I’m trying to do a little air hockey game. I have the table model (MeshCollisionShape) and I move the stick model (kinematic) using the mouse.



However, the stick model overlaps when it’s near the borders of the table. How can I avoid the overlaping?



Thank you!

Set the gravity:

[java]physicModel.setGravity(Vector3f.ZERO);[/java]

Then never add any force in the y directions.

This can be done if you constantly update it and remove the y velocity.

You can move a kinematic object into another (static) object without anything happening, you’d have to use a PhysicsCollisionListener to avoid moving on when you collide with a wall.

1 Like

Thank you for your answers.



At the end I’m using

[java]table.collideWith(stick.getWorldBound(), results)[/java]

and if they collide I set the stick position as the last one before colliding.

Now I’m facing a new problem (I don’t know if it would be better to create a new thread for that).



As I said, I’m moving the stick (a kinectamic object) using the mouse, and I’d like to hit a ball with it.

If I move the stick slow it works fine, but if I move the stick quite fast, the stick just goes through the ball.



Is there any way to fix that?



Thank you again!

well, as you are using physics I strongly recommend you to don’t check collisions with colision results, But you should use the PhysicsCollisionListener interface instead. This will help you : https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics_listeners?s[]=physicscollisionlistener

Use ccd. When the stick moves so fast that in the 60fps physics framerate the stick is before the ball in one frame and behind the ball in the next then it will not be moved…

1 Like

Thank you for your answers.



I’ve been playing with setCcdMotionThreshold, setting small values (the half of the size of my objects) but I still have the problem when the stick moves fast :S

Set ccd on both the stick and the balls.

@normen

I did it.

I’m thinking that maybe the problem is related to the way I move the stick. I’m using an analogListener to listen to the mouse movement, setting the position of the stick on the onAnalog() method with setLocalTranslation() (because it is a kinematic object).

I don’t know if I’m making a mistake doing that.

Maybe try setting a zero mass on the kinematic stick…

Thank you normen for your help. Unfortunatelly, setting a zero mass on the stick didn’t help.

I’m trying to find an example project with a similar functionality (a kinematic that moves using the mouse), but I haven’t found any yet.

@normen said:
You can move a kinematic object into another (static) object without anything happening, you'd have to use a PhysicsCollisionListener to avoid moving on when you collide with a wall.

@glaucomardano said:
well, as you are using physics I strongly recommend you to don't check collisions with colision results, But you should use the PhysicsCollisionListener interface instead. This will help you : https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics_listeners?s[]=physicscollisionlistener


It doesn't work?

@glaucomardano

The problem now is not about moving a kinematic object into a static one. The problem now is about moving a kinematic object (a stick) into a dynamic object (a ball). When the stick moves slowly everything is ok, but when it moves faster there is no collision at all.