Kinematic-kinematic interactions


hello defolders!

if i got it correctly, defold does not support kinematic-dynamic interactions, i.e. an air-hockey game where the player paddles would be kinematic and the puck would be dynamic. hitting the puck with a fast paddle movement does not accelerate the dynamic puck, the paddle pushes the puck but when the paddle stops, the puck will continue with the speed it had before the collision but correctly with the erm, “bounced off” path …

so now i read up and changed the puck to a kinematic object, i detect the collisions correctly, i used “Resolving kinematic collisions” in the physics manual, the puck bounces off rotating objects, slides along the sides of those rotating objects, all works great and as expected

but … :thinking:

i am so stuck in finding a way or to get usable values from the “contact_point_response” message :cry:

“relative_velocity” always returns vector3(0,0,0)
“distance” somehow does not seem to return usable info since it can report a deeper penetration for a collision where the object the puck collides with is moving away from the puck as for a collision that happens with an object moving towards the puck.
" applied_impulse" is always 0

attached is a screen shot of a simple test, the 2 boxes rotate with a fixed velocity, the ball bounces off the sides of the screen and the boxes. what i am trying to do is to get a value that i can use to either slow the ball down or speed it up, depending how it hits the rotating boxes, depending on if the surface the ball collides with is moving towards or away from the ball, maybe better said i’d like to make the ball bounce off depending how hard it gets hit by an obstacle or the moving player paddle …

colyseus networking and all i wanted so far was “easy” (yeah right) but its working like a charm … i just can’t figure this one out.

any help would be appreciated, thank you all in advance



When the paddles are kinematic you need to keep track of the velocity yourself since you are in charge of moving them. It might be enough to keep track of previous and current position and the delta time to get something useful.

One problem with rapidly moving collision objects is if you have an irregular frame rate or high delta time values since you may end up with deep object penetration or even worse the ball passing right through the paddle with no collision detected at all. Box2D has a “bullet” flag but it is currently not exposed in Defold (feature request: You can use ray casting to alleviate most of these problems though.



thanks for the reply @britzl, could you tell me how i would keep track of the velocity of the edges of the boxes in the screenshot? let’s say the top box is rotating clockwise with a certain speed, if the ball coming from the bottom of the screen hits the obstacle on the right side, the impact is higher as it would be if hitting the left, since the ball and the edge are moving towards each other and vice versa if it hits the left side.

the ball will never move that fast so it could jump through a paddle or obstacle. i know what you are talking about and experienced this in godot engine and it can be worked around.

in my case imagine an old pinball machine, the closer the ball is to the pivot point of the flipper, the less energy is inflicted on the ball … or a pong game where the player paddle tilts into the direction of the paddle movement, depending on how far the paddle will move (distance between paddle position and tap point on the screen … bigger the distance, more tilting of the paddle, hence more energy released onto the ball) … that tilting i would like to use to have the player to be able to “slam” the ball back to the opponent’s side with a well timed tap …



Without getting into a bunch of math that I’m not qualified to explain, I believe you could track the rotation over time, instead of the position over time, as Britzl suggested, but in the same way. Basically from frame to frame how many degrees or radians did it rotate in which direction. A higher number obviously means faster rotation. Then you could multiply that by some factor based on how far out from the center the ball hits (how_fast_it_rotated * distance_from_center).

I’m sure this would cause issues with the ball hitting an edge that was moving “away” from it, but you might just need a basic base level of “rebound” that forces the ball to always move away from the object when it hits.

There might also be a way to keep the “paddles” as dynamic objects, but change the settings of them in such a way that they don’t move, only rotate (high mass/inertia?) instead of having them as kinematic objects, but I don’t really ever use dynamic collision objects, so I’m not sure on that.



@ryanscottlandry … thank you very much, i think you put me onto the right approach

1 Like