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\$
1
  • \$\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, 2016 at 0:07

2 Answers 2

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\$
1
  • \$\begingroup\$ what's different between AngularDamping and LinearDamping and what are they? \$\endgroup\$
    – TomSawyer
    Sep 24, 2016 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\$
2
  • \$\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, 2016 at 11:26
  • \$\begingroup\$ @TomSawyer yeah, you're right. By the way, this realization worked. Ideally, I should use subtraction with if statement. \$\endgroup\$ Sep 28, 2016 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .