I’m kinda running out of options. I have a four players game that I use physics and forces for movement, hence they can’t be kinematic. But now people came up with the idea that players can’t move other players, and i need each player to ignore any external forces applied to them, if I knew that since the begining i would not use forces for movement.
Like, each player must behave like a wall to each other, but still needs physics to be calculated normally for moving himself (by addforce).
I’ve tried a few things like making an extra kinematic bound outside of them, but it’s kindda messy and random.
Applying an inverse force to the colliding rigidbody during the collision is not working very good, or I’m not doing it right.
What I really need is the rigidbody to behave like a kinematic rigidbody DURING the collision then it goes back to normal, but don’t know how to do it or how to simulate it.
I’m aware of the ignore layers matrix. Ignore “that” layer? What layer? The player layer?
If that’s what you meant it wouldn’t work to do what I want, the objects would “pass by” each other, totally ignoring the collision.
I don’t want the collisions to be ignored, I want them to ignore the external forces applied to them, making them stand still when forces are applied to them by an external agent, like another rigidbody pushing them with velocity and force.
Object A hits B, B will ignore the forces applied to him by “A” and stand still. “A” won’t be able to move because he is hitting B. In the same time, B can’t move towards “A” but can move towards any other direction that is not facing A. A and B will behave like walls to each other, not ignore each other. They will be kinematic in terms of collision to each other and still keep their physics properties.
I tried that approach, but the results weren’t satisfatory for some reasons.
Physics were still calculated normally even when I set the velocity of both of them to zero OnCollisionStay.
While the player keeps pressing the button, the force keeps being applied to him. And even setting his velocity to zero or inverting it when touching another player (OnCollisionStay as well), somehow he still pushes the other player and physics keep working normally, only slowing it down a bit.
I’ve gone to another aproach, setting a child kinematic rigidbody envolving (a little bigger than) the controllable player’s rigidbody. This kinematic rigidbody only collides with another player’s kinematic rigidbodies, using ignore layers. This way player’s kinematic rigidbodies would collide with each other BEFORE the controllable rigidbody. This way the controllable one still had all physics routines applied to it and could have forces and velocity applied to it.
This SOMEHOW worked without messing the controller and is pretty close to the final result I’m expecting, even so I’m sure there must be a better way of doing it. 100% sure this approach will give me headaches in the future.
yeah its a slightly tricky problem. You need to pre-empt the collision, most likely through raycasts and not apply force in the direction of the other player collider.
Its behaviour you should be careful with, I dont know much about your game, but this sort of character blocking can be abused by trolls in game…