applyForce does not seem to have any impact

Hi guys,

I am having hard time with applying force to a PhysicsBody. Basically, I have a sprite of size 78x16 with the following PhysicsBody

auto physicsBody = PhysicsBody::createBox(size, PHYSICSBODY_MATERIAL_DEFAULT);
physicsBody->setDynamic(true);
physicsBody->setTag(PADDLE);
physicsBody->setCategoryBitmask(PADDLE);
physicsBody->setCollisionBitmask(BORDER | BALL);

I am applying the force physicsBody->applyForce(Vec2(-900.0f, 0.0f));
But it does not seem to have any impact - the object remains in the same position.

Please advise. The online documentation says that this function applies immediate force while the source code comments state that this function applies continuous force. Which is correct? Do I understand correctly that immediate force refers to one-time force application while continuous force is applied on each object update?

PS:
I am trying to move the object while the key is pressed by the user. When the key is released, the object should stop moving. I was thinking that I could use applyForce(Vec2(forceAlongX, forceAlongY)) when the key is pressed and then reset the force applyForce(Vec2::ZERO) when the key is released to stop object movement. But it is not obvious to me if applyForce is one-time operation or applied on each object update. I cannot verify this myself as applyForce does not seem to have any effect at all.

Is it the right way to implement object movement with keyboard using applyForce? I was not able to find good explanation in the internet around the subject. I would be very appreciative if you could elaborate on how this is supposed to be done.

Tx

1 Like