-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking solid objects in half #42
Comments
Hello, Splitting a brick into pieces is game logic, and not the job of the physics system (box2d). The job of the physics system is to simulate interaction of physical bodies that the game logic defined earlier. The Physics engine should not be used to decide when to change or create new bodies based on game-specific rules like the one you are describing. Therefore I suggest you do not change any internal code of box2d, but to use box2d's ContactListener (many tutorials online. eg. https://www.iforce2d.net/b2dtut/collision-callbacks (should be trivial to translate to C# equivalent). Your ContactListener implementation will receive collision notifications from box2d. You can then check if one body is a bullet and the other body is a brick. Splitting the brick will work best by deleting the brick entirely and creating several new brickfragments as separate game objects (each with their own RigidBody). By the way: |
I agree with @thomasvt. @MadCowChicken Feel free to see examples how to use |
I didn't know it had ContactListener / ContactFilter sort of support. Thank you. |
Actually a quick look at the collision callbacks link above makes me believe it is not what I'm looking for. I don't need to add code to run after a collision is processed. I need to add code to run before a collision is processed. I need to split a brick the moment before the bullet hits the brick so that the pieces can fly apart more naturally. |
So, you want the ball to hit the brick, break it and have the same impact velocity propagate realistically to the broken pieces? I don't think you can create that without faking some things here and there. Some ideas:
|
If I create a copy of the bullet with |
Description
This isn't actually an issue, I'm just looking for guidance.
Suppose I have a rectangle (representing a brick) and a circle (representing a slow-ish bullet) and if the bullet hits the brick with enough speed I want to turn the brick from one object into two or three objects along fracture lines that seem intuitive.
Do you think it would work for me to modify the
ContactManager.Collide()
method in such a way that it does two passes... The first pass could replace the bottom part of the function that looks likewith something like
and then the second pass would be exactly the code that's in the
ContactManager.Collide()
method normally?Or would this not work? Maybe I would need to rewind positions after the first pass? Possibly by capturing the world state at the beginning of the first pass and resetting it to that (except for the broken brick) before doing the second pass?
The text was updated successfully, but these errors were encountered: