Cocos2d-x 3.17 PhysicsBody::applyForce( ... ) Still works wrong

below is my previous post.
https://discuss.cocos2d-x.org/t/cocos2d-x-3-16-physicsworld-weird/39518

PhysicsBody::applyForce( … ) should be accelerate object.

but now(in 3.17) it works PhysicsBody::setVelocity( … ) and EXTREAMLY SLOW SPEED.

What is extremely slow? Are you testing on hardware or in an emulator?

I’d tested in hardware(win32-build, macos-build, android-build).
slow means that PhysicsBody’s movement speeds.

I’d tested this code in 3.10 / 3.16 / 3.17
It seems to be an error from version 3.16.

schedule([=](float dt)->void{
    Node* n = Node::create();
    n->setPosition({50, 200});
    n->setPhysicsBody(PhysicsBody::createBox(Size(40, 40)));
    n->getPhysicsBody()->applyForce(Vec2(10000, 0));
    n->getPhysicsBody()->setGravityEnable(false);
    addChild(n);
}, 2.0f, "scheduele");   
getScene()->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

below is 3.10, This physics movement is correct.
10

this is 3.16 and 3.17 But this is weird
16
applyForce(…) does not accelerate PhysicsBody, and movement speed is very slow.

this is applyForce(Vec2(1000000, 0)),
16(2)
does not accelerate body
it works like PhysicsBody::setVelocity(…) not applyForce(…)

May be this line is problem, why you added this? If you want to apply gravity on your objects?

The problem should not with gravity. Objects can move without gravity.

If there is no gravity then force on objects will work as velocity, right?

Let’s assume world does’n have gravity and friction.

Then force changes acceleration of an object. Acceleration changes velocity. If no force, then no acceleration, then velocity will not be changed (will be constant).

@androidLaLa try ApplyImpulse instead of applyForce:
http://www.box2d.org/forum/viewtopic.php?t=260

@dimon4eg
It can be replaced with applyImpulse( … )
However, I want to report a bug in applyForce. ( … )
It should be fixed

@smitpatel88
PhysicsBody::applyForce( … ) Applies a continuous force to body.
applyForce means to change the acceleration in a narrow sense.
For example, Gravity is the force, All objects in the air in Earth accelerate as they fall.

I have the same issue with applyForce(). The body does not get a constant force applied, instead it behaves like applyImpulse() except the function parameters need high number to work like the impulse.

I have checked the CCPhysicsBody.cpp but the file seems to correctly call the physics library.

I am building for Linux x86_64 and Linux ARM. The applyForce() function does not work correctly on both.

With the Linux x86_64 i use the prebuilt Chipmunk Library and on the ARM System i use my self compiled Chipmunk Library v 7.0.1.

I would like try other Chipmunk versions but i still need to setup up my build environment.

Or does have anyone some ideas what i could try to figure it out? :thinking:

2 Likes

Same issue here. Moreover when I repeatedly restart scene with Director::getInstance()->replaceScene(MainScene::create()); it behaves very nondeterministic sometimes object moves fast and sometimes half time slower.

Any luck with this issue?

Hey guys, I think this is the intended behaviour, the force is applied only during the current frame. That means that you should call applyForce every frame!
It behaves nondeterministic with high values because the frame duration may vary, in other words, the variation of the speed is the time interval times the acceleration (force/mass).