At this point, I’m looking for a way to implement physics methods in Defold, as in the Contact Listener Box2d class. Previously, for the production of games used frameworks, and the map editor created itself, but now I want to try to make a few games on the Defold. The only thing I don’t understand is the lack of ContactlListener. Here’s an example of what you can do with physics, it:
beginContact
It works when two objects start to overlap. Proceed only within a step.
endContact
Triggered when two objects stop touching. Can be triggered when the body is destroyed, so this event can take place outside the time step.
preSolve
Triggers after a collision is detected, but before it is processed. This allows us to somehow change the contact before it is processed. For example, you can make a contact inactive.
postSolve
The method allows you to implement the logic of the game, which changes the physics after contact. For example, deform or destroy an object after contact.
For example, the endContact and preSolve methods, in the platformer genre game, allowed the player to very accurately report the state of ground contact, as well as jump through the platform if you jump from the bottom up, and turn on the collision if you find yourself on top of the platform.
Please, if there are workarounds for such implementation, it will be very useful for me, thanks
We provide a simplified version where we have the following physics body/collision object types:
Dynamic - Entire physics simulation handled by Box2D. Manipulate the game object by posting apply_force messages. You can post a disable message to temporarily turn off physics and manipulate the game object using go.set_position() etc. The game object will receive contact_point_response and collision_response messages containing collision details.
Kinematic - Collision detection handled by Box2D. Manipulate the game object using the go.* functions. The game object will receive contact_point_response and collision_response messages containing collision details.
Static - The game object cannot be moved from it’s initial position. Use for immobile level elements, game area borders etc. The game object will receive contact_point_response and collision_response messages containing collision details.
Trigger - Simple collision detection. Will generate trigger_response messages with enter/exit state. Perfect for detecting level triggers, proximity events etc
All collisions are communicated via message passing. This means that your chance to react to collisions will be in the on_message function of your scripts. In the case of contact_point_response messages you get plenty of information about the collision (normal, distance, applied impulse, mass etc) and can react accordingly to separate objects and do all sorts of interaction.
If you use kinematic collision objects and check the collision normal it’s fairly simple to implement one-way platforms.
Also remember that you can do ray casting to detect collisions ahead of time!