Collider, manual velocity and mass

I have a player with mass 100.

And a rat, mass 1.

Both player and a rat has circular gameobject and arcade bodies. I setup the physics group collider and put them into that group.

I also set the mass to that bodies.

Now I have implemented the rat behaviour. It tracks the player and wants to reach the center of the body. It collides with the player body and moves it. To propulse the rat I give it some velocity every tick (prior velocity + acceleration). I set it up as a physical.body velocity

What I expect that player will be knocked proportionally to his mass - a little bit every tick, lot smaller than the rat can propulse itself.

What I see that the rat kicks player like it has the same mass.

I suppose something wrong with the propulsion logic.

Should I get the rat not velocity but something else? What is should be? I want it to have acceleration and speed in the ‘open wilds’ but when it hits the player, player shall be pushed just a little.

I have found that the issue may be caused by the thing that every object collides two times instead of one. Trying to fix that.

Arcade Physics World.js:
collideObjects: function
Collision code when two gropus collide:

//  They're both arrays
            for (i = 0; i < object1.length; i++)
            {
                for (var j = 0; j < object2.length; j++)
                {
                    this.collideHandler(object1[i], object2[j], collideCallback, processCallback, callbackContext, overlapOnly);
                }
            }

Every pair called twice so there is a source of double collisions when I collide the group with itself.

Update: I have solved the issue. I have found that I can pass undefined instead of the copy of the first group and the method collideGroupVsGroup // Collide Group with Self will be called.

Now the behaviour is correct, takes me about 8 hours to figure out :laughing:

1 Like