Pin Ball Game. Paddle not hitting ball, best way to move paddle

Was just doing a simple project and want to hit a pin ball with a paddle.
I created a simple paddle model in blender. A rectangle with the origin point closer to the left side.

I attached the paddle as a Kinetic physics object:

      public void initPaddle() {
   paddle = assetManager.loadModel("Models/paddle.j3o");
    Material defaultMat = new Material( assetManager, "Common/MatDefs/Light/Lighting.j3md");
    paddle.setMaterial(defaultMat);
    paddle.setLocalTranslation(0f, .2f, 5f);
    rootNode.attachChild(paddle);
   

    RigidBodyControl spinnerControl = new RigidBodyControl(0);
    paddle.addControl(spinnerControl);
    spinnerControl.setKinematic(true);
    spinnerControl.setFriction(0);
    paddle.setLocalRotation(PITCH045);
    bulletAppState.getPhysicsSpace().add(paddle);
}

The balls are just dynamic physics objects.

I just have the update constantly rotating the paddle

paddle.rotate(0,-tpf*paddleSpeed,0);

The results that I am seeing is that it kind of squeezes the ball instead of knocking around.
So in stead of hitting it like a bat. It kind of pushes it around.

Am I expecting to much from the physics engine? Anyone have any pointers.

Second Question.
How should my code look for the pressing of the button that triggers the paddle?
Do I use slerp and time since the button was last pressed? If so is there any code I can look at that combines slerp with button mashing.

Thanks,
Greg

It’s hard to picture what you mean by [quote=“gbluntzer, post:1, topic:32113”]
it kind of squeezes the ball
[/quote]

Any chance you could post a quick video?

Update: If I check vsync then the physics works a bit better. The ball gets batted around. Maybe the refresh rate was to fast.

For video recording I have lost my code that uses the VideoRecorderAppState does anyone have an example of using it.

You are doing it wrong. Please read the chapter “Forces: Moving DYnamic Objects” in the tutorial here:
http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:physics

You can not use setLocation, setPhysicsLocation, rotate or any of those methods because they ignore physics - right now you are not actually using the physics engine since you are basically resetting it every frame.

I guess I do not understand the “Kinematic vs Dynamic vs Static” section
I read the “How does it move?” row as saying that you move it with setLocalTranslation(); and was assuming rotate(…) was the way to rotate it.

Can someone enlighten me on the correct way to rotate a pin ball paddle at run time.
Thank you,
Greg

Oops, my bad, I missed the kinematic-part. Sorry. The problem isn’t as simple as I thought. Anyhoo, a kinematic object has no torque, velocity et c. So it can not “bat” a ball. A kinematic object teleports into location and the physics engine will try to resolve any overlaps by moving objects apart until the conflict is resolved. That is why a kinematic object can for example serve as a platform for an object to rest on. A ball can probably bounce on a kinematic object but a kinematic object can not impart any impulse since it is semi-magical and teleports around instead of physically rotating. So yeah, you still have to use ‘real’ physics i.e. apply forces to the paddle instead of just teleporting it into location each frame.

It kind of goes this way:

  • when you initialize your game, you use setPhysicsLocation and setPhysicsRotation to put everything in place.
  • then, once the game really launches, you react to inputs and stuff by either calling methods on already made jme controls (VehicleControl, (Better)CharacterControl) by calling their special methods, or you directly call methods such as applyForce, applyCentralForce, applyTorque etc on something inheriting from PhysicsRigidBody (usually RigidBodyControl) or you make your own Control that inherits from RigidBodyControl (usually) and call it’s special methods, and that object then calls the previously mentioned methods.

That way, you can put everything in place and have the physics engine take care of movements, pushing other objects and stuff.

What loopies says is true. I made a pinball game in unity and the same principle can be applied here.

  • have a base object (it can be empty node) that is either a static rigidbody or a kinematic one (if you plan to make an editor)

  • the paddle is a dynamic rigidbody anchored to the base object in physics with a joint, don’t forget to add constraints.

  • have a control object apply torque to the paddle which will hit the ball as desired Upon contact

This isn’t exactly true when you ue kinematic mode. For the physics the kinematic objects are the same as other physical objects with speeds and forces according to how they are moved by the user. So using a kinematic bat with a rigidbody ball is probably the best solution in cases like this where you basically need 100% control over the object that is moved by the user. Of course you’ll have to care for the collision detection of the kinematic objects yourself. But in this case that just means keeping the slider on the table…

At ay instance the code should work fine with kinematic mode as it is because you already use setPhysicsLocation anyway… Maybe you can test if you see a difference beween jbullet andnative bullet in this case.

Oh, I didn’t know that. Sorry to give out misinformation about how kinematic objects work.

Maybe it would be an idea to apply a rotational force to a physics joint via a motor, rather than to the paddle object directly?

You wouldn’t need to do any special physics collision checks then (and it would probably reflect real life more accurately anyway)

The easiest way to otherwise create a relatively easy to control physics object is to set the velocities for a rigidbody continuously. According to the bullet developer thats not exactly elegant but should not result in problems either. Still seems to be exactly what kinematic mode is meant for though.