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.
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.
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.
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.
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.