Closed tevch closed 8 years ago
You should use an engine event to apply it on every update.
Hopefully that answered your question so I'll close this, but feel free to comment if you still need more info.
I have a similar question where i would like to add gravity once an animated object reaches the center of the screen. Is this possible?
Sure you can use events for this, check the distance of body.position
to the target point every tick, when it gets lower than a threshold set a flag and then add forces.
Thank you! Ill be trying this today :)
I think I might be confused as to how to check the position of the body and how to apply the gravity force once it is in the ideal position. Syntax-wise
goal:
Hey, I have a question, can u please just take a second and tell me how to use the engine event to apply constant force, for instance say , I want to apply force on a particle in electric field, so, How do I apply the force on that particle. Thanks
Matter.Events.on(engine, 'beforeUpdate', function(event) {
//Apply force
});
This event is sent on every iteration of the simulation loop. More at: https://brm.io/matter-js/docs/classes/Engine.html#events
How to applyForce on an circular object
I feel like this is a bit weird. Why do I have to iterate and set force in all my physics entities with forces applied to them before an engine update? I feel like body.force shouldn't be reset to (0,0) after a physics step.
@davidreis97 there's a plugin that makes things easier check out matter-attractors
I know how to apply force, but looks like it applies once, losing momentum with time
what i want to ask is - how to apply(introduce) constant force, like gravity. for instance - lift, or thrust, or drag of flying body.
Thanks