Replies: 1 comment
-
You should be able to override @override
void postSolve(Object other, Contact contact, ContactImpulse impulse) {
// Calculate the collision force
final normalImpulse = impulse.normalImpulses[0];
final tangentImpulse = impulse.tangentImpulses[0];
// Assuming the mass of the bodies is available
final bodyA = contact.fixtureA.body;
final bodyB = contact.fixtureB.body;
final massA = bodyA.mass;
final massB = bodyB.mass;
// Calculate the force using the impulse and mass
final forceA = normalImpulse / massA;
final forceB = normalImpulse / massB;
print('Collision force on bodyA: $forceA');
print('Collision force on bodyB: $forceB');
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are many small balls in a container. I want to add a vibration effect when the small balls collide. However, when a collision occurs,
beginContact
orendContact
will be called a large number of times. I want to add vibration only to the collisions with greater impact and ignore those with smaller impact. But I have tested many properties and consulted the documentation and haven't found a correct way to obtain the impact force and speed.remarks: use flame_forge2d
![image](https://private-user-images.githubusercontent.com/4014593/373931089-8c6a9532-909a-4240-b807-94eb74287653.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MjU4OTYsIm5iZiI6MTczOTYyNTU5NiwicGF0aCI6Ii80MDE0NTkzLzM3MzkzMTA4OS04YzZhOTUzMi05MDlhLTQyNDAtYjgwNy05NGViNzQyODc2NTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTMxOTU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjEzZWMxZjM3MGIwOGU4MGRjM2I2Y2RkYTcxZjM2MTYxNmEzYWFmNjU5OTY1MzIyYmFmNTEyYzJlMGU4NmZiOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.PHR0MJGbuZStXRyLcyu1uhzgfhaRx2LEW6uRReoY7DU)
Beta Was this translation helpful? Give feedback.
All reactions