Apply force not working has expected?

It been over a week since I started using defold, and I’m enjoying every bit of it :grin: a different way of doing things but I dig it, haven’t ran into any problem untill apply_force

msg.post("#collision","apply_force", {force = vmath.vector3(0,1,0) * 50000, position= go.get_world_position()})

for the proposes of learning I gave myself the objective to make a jumping ball, simple enough right but it seem not to work how I expected it to, the ball jump heights are not predictable at all, it jumps at different heights almost everytime

and get even worse when I build it for the web

with hours of debugging (like 15 min) I found out the apply-force force is some how affected by the dt (delta time) the higher the value the more force is been applied to the ball(but it kinda looks like a rock doesn’t it), I was able to fix it by multiplying the dt(delta time) with a hundred and dividing that with my directional force
Is that simple (I’m not a very technical guy so please bear🐻 with me)

msg.post("#collision","apply_force", {force = (vmath.vector3(0,1,0) * 50000) / (dt * 100), position= go.get_world_position()})

And boom

It works even for my web build

Jumps at the same height every time I don’t know if this is how the defold physics engine was supposed to work or it’s a bug but anyways this is the way to fix it

I hope someone found this helpful

5 Likes

Yes, including the delta time in the force calculation is the correct way to apply a force to a collision object.

2 Likes

Great good to know I’m on the right track :grin:

2 Likes