2D physics requests

I’d like to start this thread to collect all 2D physics-related needs in one place.

I’ll start:

  1. Changing linear and angular velocity in runtime.
    Setting linear velocity by code is the best way to make jumps, spawn bullets (with linear trace), arrows (with parabolic trace). Also setting linear velocity is a good way to limit velocity value.
    It could be, for example:
    physics.set_linear_velocity(dest, vmath.vector3())
    go.set(dest, “linear_velocity”, vmath.vector3())

  2. Possibility to change masks and groups in runtime.
    There are a lot of applications where you need to change mask/group of the physics in runtime. For example, in my current game I have a solid box. Player can move it here or there. But if player punch it - the box slides and crushes everything on it’s way. The best way to make it - change mask of the box just after punching (to move through other object on it’s way).
    physics.set_mask(dest, maskValue)
    go.set(dest, “mask”, maskValue)

  3. Creating shapes in runtime.
    I’m making platformer game. I use tilemaps. In this case it is necessary to union physic-tiles. To do it I have 40 pre-generated go objects with different rect-shaped physics. And 40 factories for them… and generated go object with 40 factories in it. Just because I can’t create a shape in runtime by code.
    Please, implement something like this:
    physics.create_shape(dest, ppoints)

  4. Disabling auto-sleep mode for objects.
    Really useful for game main objects. For example, to identify “standing on the ground”. I receive collision_response just until object got in sleep. After that I can’t know - is the object on the ground but sleeps, or object felt or something.
    Solution: Switcher in editor, or physics.set_auto_sleep_mode(dest, modeBoolean)

p.s. I was searching for topic like this, but I haven’t found it.

7 Likes
  1. Since the last release, we’ve added support for dynamic transforms (e.g. setting scale, and translation/rotation).
    By doing this, we essentially removed the demand for a “stable” physics simulation.
    This demand is, I assume, what has previously held us back when it comes to setting properties such as velocities/acceleration etc at runtime.

  2. Having a mask api could for sure be useful.

  3. I can for sure see an api where we allow creating shapes at runtime.
    Our default physics for tilemap shapes also needs some love, to make it a lot better though.

  4. I haven’t seen this request before, but I trust your use case :slight_smile:

6 Likes

Issue: https://github.com/defold/defold/issues/4170

Issue: https://github.com/defold/defold/issues/3459

Related: https://github.com/defold/defold/issues/3519
What you want: https://github.com/defold/defold/issues/4819

We don’t have a ticket for this one yet. Is there a workaround? Nudging the object with a minimal force? Disable/enable collision object in the same frame?

4 Likes

I guess ability to create shapes (just rectangle as minimum) can be useful for cases when the level creates from objects (not tiles) in separated level-editors like Tiled or in-game solution. So, in this cases you will need to implement colliders for walls, ground, static platform, etc.

For example, this level created in Adobe Flash, pink rectangles are shapes for creating a static colliders in runtime.

6 Likes

It will be useful to be able to modify in runtime the number of velocity and position iteration for the Box2D’s b2World::Step() method.

Box2D manual suggests to use 8 for velocity and 3 for position:

The suggested iteration count for Box2D is 8 for velocity and 3 for position. You can tune this number to your liking, just keep in mind that this has a trade-off between performance and accuracy. Using fewer iterations increases performance but accuracy suffers. Likewise, using more iterations decreases performance but improves the quality of your simulation.

Defold’s default values are 10 for velocity and 10 for position.

“Pros”:

  1. A high number of iterations help to stabilize dynamic objects (https://imgur.com/a/2QabvlO).
  2. Here can be a performance gain with lesser position iteration.

For example, in Angry Birds-like game you can initially set both iteration count to 100 to make Box2D world visually stable. Then reduce count to 3 on the first collision callback to make world more wobbly :slightly_smiling_face:

6 Likes

Solved in 1.2.171

5 Likes