I have the ball, that is “dynamic” obj, and the rackets, that was “static” obj.
All worked fine.
Now I would like to upgrade the bouncing effect on the rackets and I tried to works with the linearvelocity.
But the obj:getLinearVelocity() does’t works with “static” obj, so I changed it in “kinematic” the rackets. But also on this I receive 0 from function.
On “dynamic” obj my rackets goes around the screen impacting with the ball. Non nice!
When you have problems like this, then you should provide code that demonstrates your issue. This is simply because :getLinearVelocity() method behaves exactly as expected, so the issue is somewhere in your code.
See the link about physics body types I linked you above.
You’ve created a kinematic body, which doesn’t react to gravity or collisions with other objects. They only react to the linear velocity that is applied to them.
In your code, you are moving the object by manipulating its coordinates instead of using the physics engine to move it. This means that you are not applying any physics forces to it, so its linear velocity will remain zero.
thanks Xedur, I understand this logic that manages the physic world.
Do you have any idea or tutorial that explains how to move objects, moved by a player, while keeping them in the physical world? the only tutorial I found is that of the site I mentioned above.
Or how can I lock an object on its axis when it receives an impact?
Well, you can use a joint to drag physics bodies around. You can find an example for that in the sample projects in the simulator, or check out the Crate sample project at https://www.solar2dplayground.com/.
If you are creating paddles for pong, then what do you need to get the linear velocity for anyway?
If you need to control the objects via :setLinearVelocity(), then just apply it towards the touch movement. If you have dynamic object that you want to prevent from rotating, just use https://docs.coronalabs.com/api/type/Body/isFixedRotation.html. If you have static or kinematic bodies, then they won’t react to collisions anyway.
If you want to remove gravity from some dynamic bodies then look for gravity scale option. If you need to stop the movement of an object at any point, then just set its linear velocity to 0, 0.
the object.isFixedRotation() helped me, but when the ball bounce with the baddle this one moves from the place.
The basic games works well but I want to add some effects when the ball bounce on paddle, otherwise the bounces have no effect and are boring.
The first thing to know is the speed of the paddle which will influence the resulting speed of the ball after the bounce. That’s why I went to look for the linear speed of the baddle (which is nothing but its physical vector).
I tried to play with bounce, friction and density but I’m not arrived to have pretty bouncing ball effects.
I arrived to get the angular speed using the physical motor: I put the mass of the paddle to infinity (a value around 5000) keeping at the same time the object “dynamic”; and the linear speed came out! The object - having almost infinite mass - behaves as if it were “static”, without having its limitations.
So now I can play with vectors!
Thank you for help.