Dynamic collision object jitters while on rotating kinematic collision object [ON HOLD]

I have two elements in my game, one is a ball, the other is a cogwheel. My goal is to be able to transport the little ball by moving it on the cogs of the cogwheel, as seen in the following gif.


My issue with that is that when the ball is about to roll off, it starts to do several little bounces, which makes the motion look jittery. What I’m aiming for is for the ball to smoothly roll off the cogs. Neither of the objects have any restitution. I assume this is simply caused by the cogwheel rotating and the ball following it afterwards (I rotate the cogwheel through the animate function). My attempts mostly consisted of utilising the collision responses to push the ball down the according normal direction, either by applying force or setting its position. But both of these approaches resulted in the ball being just stuck to the surface of the cogwheel without ever falling off or actually moving.

Would anyone here have an idea that I could try to prevent this behaviour?

How are the cogs built?
How is the ball defined? A dynamic collision object?

The cog is a game object that has multiple collision objects attached to it, which are set to kinematic. The center of the cog has a sphere as collision shape and each cog has a box as collision shape.

Yes, the ball is a single dynamic collision object.

Although we don’t have the feature in our editor (yet), it’s still possible to use constraints from the scripting api.
I think you should be able to use dynamic shapes, and then use a constraint e.g the JOINT_TYPE_FIXED to lock it in place.

1 Like

I think your guess is right. Since the kinematic cogwheel doesn’t have velocity, the physics simulation controlling the dynamic ball doen’t know the cog is moving, so it falls down and bounces every frame. I think you need to make the cogwheel a dynamic object. I think you can control it with a hinge joint with the “motor” enabled.


Allright! I’ll give the joints a try and report back on how it went. :slight_smile:

1 Like

Perfect timing that @Pawel contributed a hinge joint example yesterday:


Alright, using your suggestions and the example I came a bit closer to the desired behaviour! But now, as I had to make the wheel collision objects dynamic, they are affected undesirably by other dynamic objects (i.e. the ball) and gravity itself, which you can see in the following:

My desired behaviour would be as shown in the first .gif of my post, where the wheel is placable everywhere not affected by gravity or by the balls force. Is there a way to achieve this even though my objects are now set to dynamic, perhaps by using another joint of the type fixed that can act as a sort of nail?

Just wanted to bump this thread as the initial problem is still an issue for me which I’m not sure how to resolve. Is there any way to move my cogwheel object so that it is synced with the ball to avoid the stuttering (as the issue seems to be between an object moved by physics while the other rotation properties are being animated)? While the solution utilising hinge joints would make this possible, I now don’t know how to lock my wheel into place. Let me know if more information is necessary on my end. :slight_smile:

I’ll take a look soon!

1 Like

What is your hinge joint attaching the cogwheel to? Can’t you pin it to a static object?

1 Like

Exactly! I tested this just now and it stays in place as expected! @Joskony that’s the solution for you. Create a tiny static sphere collision object that you attach the hinge joint to.


Ok! I don’t know why I was assuming that joints didn’t work with static objects, thanks! This makes the cogwheel lock into place. In addition to that, I made the mass of the wheel itself higher so that its rotation won’t be affected by the balls physics, but is only moved by the motor itself.

Unfortunately, the result of that does not prevent the ball from bouncing:


My setup looks like the following:


local body = "#collisionobject_default_1"
local gear_1 = "#collisionobject_default_2"
local gear_2 = "#collisionobject_default_3"
local gear_3 = "#collisionobject_default_4"
local static = "#collisionobject_static_1"

local center_anchor = vmath.vector3(0, 0, 0)
local gear_1_anchor = vmath.vector3(0, 0, 0)
local gear_2_anchor = vmath.vector3(0, 0, 0)
local gear_3_anchor = vmath.vector3(0, 0, 0)

local hinge_props = { enable_motor = true, enable_limit = false, max_motor_torque = 1024, motor_speed = -math.pi / 4}

function init(self)
	physics.create_joint(physics.JOINT_TYPE_HINGE, static, "0", center_anchor, body, center_anchor)
	physics.create_joint(physics.JOINT_TYPE_HINGE, body, "1", center_anchor, gear_1, gear_1_anchor, hinge_props)
	physics.create_joint(physics.JOINT_TYPE_HINGE, body, "2", center_anchor, gear_2, gear_2_anchor, hinge_props)
	physics.create_joint(physics.JOINT_TYPE_HINGE, body, "3", center_anchor, gear_3, gear_3_anchor, hinge_props)

Maybe it’s just not possible to achieve a smooth falling off motion from the cogs in Defold or only through several iterations and adjustments to the colliders/physics to tune them specifically?

1 Like

have you tried to set the restitution (bounciness) of the ball?

1 Like

Restitution of the ball and wheel itself are both set to 0.

€: I’ll take care of creating a minimal example project for the issue and link it here later, maybe that would help. :slight_smile:

€,2: Cogwheel.zip (3.6 MB) A minimal example that contains the ball and cogwheel the way I have it setup in my original project.

Yes, it does indeed jitter/bounce slightly while in contact and the wheel is moving. I’m not entire sure how the values can be tweaked to avoid this (a higher physics scale maybe?). We’re soon exposing the velocityThreshold value in Box2D so that it can be tweaked. Decreasing this value from the default value of 1.0 may alleviate this, although I’m not 100% sure.

1 Like

Alright, thanks to everyone for the help! The issue is something I can live with (sort of) so it’s really not crucial, but I’ll definitely try out the velocityThreshold value whenever it becomes available. :slight_smile:

I’ll mark my question as ‘on hold’ for now.

1 Like