applyForce on collisionStart event
See original GitHub issueHi liabru, I have a question. How can I use “Matter.Body.applyForce” within “collisionStart” event ??
From this I can use “Matter.Body.translate”, but not “applyForce”.
I tried this but it does not work for me:
Events.on(engine, ‘collisionStart’, function (event) { for (var i = 0; i < event.pairs.length; i++) { var pair = event.pairs[i];
if (pair.bodyB.label == 'regla' && pair.bodyA.label == 'dominoTableB18' ) {
Matter.Body.applyForce(lemmon, { x: 0, y: 0 }, { x: 0.1, y: 0 });
}
} });
Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Apply force on CollisionStart event - Phaser 3 - Discourse
what i'm trying to do is making a sensor that give force to an object when it collides. i've tried to apply force...
Read more >Implementing bullet collisions in Matter.js for a shooting game
applyForce ( bullet, this.body.position, { x: Math.cos(this.body.angle) ... Events.on(engine, "collisionStart", event => { for (const {bodyA, ...
Read more >Matter.js Physics Engine API Docs - brm.io
Events.on(Engine, " collisionStart ", callback). Fired after engine update, provides a list of all pairs that have started to collide in the current...
Read more >RigidBodyComponent | PlayCanvas API Reference
Teleport an entity to a new world-space position, optionally setting orientation. Events. collisionend. Fired when two rigid bodies stop touching.
Read more >Game object - Notes of Phaser 3 - GitHub Pages
applyForce (force); ... scene.matter.world.on('collisionstart', function (event, bodyA, bodyB) { // var pairs ... event.pairs : An array of collision pairs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m still having trouble getting this to work using the method you describe. Am I misunderstanding the logic?
As it stands, forces get cleared in
Engine.update
right after the event is emitted, so they won’t ever get applied.This probably should be changed, but for now you should cache the forces you need to apply in some place outside of the event or in some custom body property, then apply them in the next engine
beforeUpdate
event.