Physics glitch when trying to slide against walls

Hi!

I’ve been coding this multiplayer .io game recently and I just encountered a problem that I can’t wrap my head around.

So in this game, you control a 2D car which uses the physics calls to move, so applyForce.

Once you go against a wall it stops correctly as expected, but when you align in a way that you should slide off that wall, it sometimes work and others the rigidbody of the car bounces off the wall and it’s in that moment that if you collide with the wall again, the rigidbody velocity gets fucked up and reaches a very high speed in a split second.

I’ve recorded a big ass gif to show you the problem:

Now, all of the game logic runs server-side, the revision of PlayCanvas that I adapted to work headless is 0.205.1 96ca6ae - just in case someone fixed the issue in recent versions, in which case I will have to port the latest version to the server.

The wall’s collisions are made with boxes just like this:

this.arenaWalls[4].addComponent("collision",{
      type:'box',
      halfExtents: new pc.Vec3(500, 0.5, 0.5)
});

with a rigidbody component set as kinematic.

The cars are capsules (first tried with boxes too, made no difference), like this:

entity.addComponent("collision",{
        type: "capsule",
        radius: 0.25,
        height: 1,
        axis: 2
        //halfExtents: new pc.Vec3(0.5, 0.5, 0.25)
});

And finally the rigidbody for the cars looks like this:

entity.addComponent("rigidbody",{
        type:"dynamic",
        linearDamping:0.92,
        // limit physics to be 2D
        linearFactor: new pc.Vec3(1, 0, 1),
        angularFactor: new pc.Vec3(0,0,0),
});

Do you have any possible idea of what could be going on?

Side note: If you just want 2D physics, consider using p2.js. @will did some integration code in this project: https://playcanvas.com/project/446127/overview/p2js-integration

It be lighter and smaller than using bullet.

On the issue, it looks like a large force is being placed on the car while it is still colliding with the wall so when it finally gets a chance to resolve, it flies off with a large resultant force. Either that or the car is getting stuck in the wall and since the wall can’t move, the car will just ping off when it becomes on stuck.

Like here for example, it looks like the car is stuck or being forced into the wall: