How to simulate a fan effect that changes the gravity?

I need to simulate the effect of a fan that makes fly a little sphere on it.
So basically image a fan on the bottom and a ball on the top. you turn on the fan and the ball starts to fly shaking a lil bit. so the ball will remain at a certain distance from the fan but will shake.
Is this possible?
You can apply forces to bodies using applyForce(), so yes it's possible for you to calculate the correct force that needs to be applied to the ball each step (in relation to the fan) in order to achieve the effect you are looking for.
whre do you put the applyforce? at runtime or on update?
lorenz82 wrote:
whre do you put the applyforce? at runtime or on update?


Isn't this this same thing? do body.ApplyForce() every time step (frame)
thank you 🙂
The force is actin very very weird...
i have a ball with a fan near, but the ball act super weird, sometimes it stops somother times makes huge jumps not even real.
Plus i have a wheel near that turns around, but the force doenst make it move.

i am using this code:
Code:
var forcex=Math.round(body1.m_userData.x-fan.m_userData.x);
var forcey=Math.round(body1.m_userData.y-fan.m_userData.y);                     
if(Math.abs(forcex)>=1&&Math.abs(forcey)>=1){body1.ApplyForce( new b2Vec2(10/forcex, 10/forcey), fan.GetPosition());}


I have noticed that the second parameter fan.GetPosition() doesnt make any differences, i can write whatever i want the result is always the same.
Anyone knows what should i do?
Show us a demo of the problem, it would be easier for us to be able help you.
i kind of solved using the globaltolocal pointing to see where the object was and calculating the correct force...
but now i have a weird problem. i have someobjects with a revolutejoint attached to the ground. but the aookyfirce doesnt affect them at all.

How does it work the applyforce with obejct jointed to the gorund?
I have tried the applytorque, it works good the first 3 seconds, then the object starts to spin faster and faster and suuuuper faster!!! why?

Original thread: https://box2d.org/forum/viewtopic.php?t=2941