# How to program friction in an air hockey game in Cocos2d-x 3.11?

I'm developing a simple air hockey game, and I have a question about friction of puck and puddles with the game scene. How can I do that? I'm using cocos2d-x default physics engine, and the friction setting of physic bodies only applies when they collide.

I've found an old air hockey example project, but it seems that it's ported to cocos2d-x 3.x so it doesn't use built in physics engine.

• Welcome to GDSE! We do only one question per question post here, so I removed the second question. You can post another question with your other question. – Vaillancourt May 17 '16 at 0:07

the methods you're looking for are:

setAngularDamping(float damping);
setLinearDamping(float damping);


according to cocos2d-x documentation both methods are used to simulate fluid or air friction forces on the body.

• what's different between AngularDamping and LinearDamping and what are they? – TomSawyer Sep 24 '16 at 19:56

So I realized how to do it. You need to override a method called Scene::update() with something like

ball->getPhysicsBody()->setVelocity(ball->getPhysicsBody()->getVelocity()*0.995f);


And later paste this into your Scene::init(), so the update() method will be called every frame(?).

this->scheduleUpdate();

• By this way may slow down the object but its like forever slow down, the velocity is never equal to 0,0 – TomSawyer Sep 26 '16 at 11:26
• @TomSawyer yeah, you're right. By the way, this realization worked. Ideally, I should use subtraction with if statement. – Alexey Elesin Sep 28 '16 at 9:12