1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Vaillancourt May 17 '16 at 0:07
1
\$\begingroup\$

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.

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

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();
\$\endgroup\$
  • \$\begingroup\$ By this way may slow down the object but its like forever slow down, the velocity is never equal to 0,0 \$\endgroup\$ – TomSawyer Sep 26 '16 at 11:26
  • \$\begingroup\$ @TomSawyer yeah, you're right. By the way, this realization worked. Ideally, I should use subtraction with if statement. \$\endgroup\$ – Alexey Elesin Sep 28 '16 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.