#Collision response between players Rigidbody2D
1 messages · Page 1 of 1 (latest)
Prevent it all together? Or prevent it for non-authoritative instances?
Simply using a NetworkRigidbody is all you need to do for the latter.
Prevent il all together. Unfortunately, it is still happening when using NetworkRigidbody
Yeah, they'll still collide on the server which would be synced via position to clients. There's many ways to avoid collisions between objects. I'm assuming you need the collider to collide with other things, so the easiest would be Physics.IgnoreLayerCollision or Physics.IgnoreCollision
I could consider ignoring player collisions, but I wonder if I can still have player collisions but without the force response
If I can give an example, like in Pokemon games where you can't push any of the NPC
Ah, I see what you mean now.
Just make them kinematic
yea. Kinematic rigidbodies can only be moved through code. They have infinite mass so they won't be bumped around
I will try it
It solved one of my issues, thank you
But players can still push each other and I have no idea on how to prevent it
Shouldn't be possible with kinematic rigidbodies. How are you moving your players through code?
What version of NGO are you on? I think Network Rigidbody used to set the owner object as non kinematic automatically
I'm using Rigidbody2D.MovePosition to move the player
_rb.MovePosition(_rb.position + movement * speed * Time.fixedDeltaTime);
I'm on 1.13.1
Even if that was the case, another player shouldn't be able to push another. The owner should just bounce off non-local players.
But either way, you can probably just remove NetworkRigidbody entirely since you do not want players moving each other or the local player bouncing off other players.
And make sure they're all kinematic manually.
I just tested it and the players can't collide with each other now
It looks like collisions between players are ignored
I thought that might happen with all kinematic rigidbodies but wasn't sure. I thought Rigidbody.MovePosition would prevent them from phasing through each other even if they were kinematic, but I guess not.
Right, yea. movePosition ignores colliders. You'll need to AddForce()
I'll give it a try
I'm struggling a bit, currently reading the doc
AddForce() is working only with a Dynamic RB
Local player will still need to be non-kinematic to move
MovePosition does not ignore colliders. Collisions are being ignored because all players are kinematic. I think you want to go back to using a NetworkRigidbody and MovePosition. If players can push each other in this setup, you've got something else going wrong.
Are you using MovePosition in FixedUpdate and using Continuous Dynamic for the collision detection mode?
I'm using MovePosition in a ServerRpc method inside of the FixedUpdate() loop
And I was using Discrete for Collision detection mode
Do I need to use Dynamic body type?
So the Rigidbody shouldn't be server-authoritative then?
With server-authoritative, only the host's player has a Dynamic body type
Switching authority setups is irrelevant here. I'm just saying set the Collision Detection to Continuous.
The problem is that all players that are not hosts are set to Kinematic mode automatically, both on client side and host side
I can't make them Dynamic
That means you're not fully set up for server auth then.
All of your players should be owned by the server.
Sorry, I'm kinda new to Netcode, can you give me an example?
By default I believe all player objects are owned by their clients. Which is making NetworkRigidbody do what you described above.
Which if you're doing server authority, you do not want.
Honestly it's probably easier to forego messing with ownership and NetworkRigidbody. All you should need to do is set isKinematic = !IsServer
In the later versions of NGO, there is a checkbox on network rigidbody to prevent auto update to Kinematic
In this case only the host's player can collide with other players, won't clients ignore collisions?
I'm currently on 2022.3, should I consider upgrading to 6?
There are very few reasons not to.
I learned recently that runtime fee isn't a thing anymore
This shouldn't be the case. This would make every player object on the server be dynamic which is where all the movement is being done and therefore the collisions.
in a server auth set up, you don't want local clients colliding with things. All the movement and physics are handled on the server and the resulting position from any collisions on the server is then synced to clients via NetworkTransform or other position syncing.
isKinematic = !IsServer should run only on the host's side if I understood correctly
It'll run on all sides. Just a different value for server vs client.
False for the server, true for all clients.
So all clients will have a Kinematic body type?
Yes.
On client side too?
Just on the client side.
I'm testing it real quick to see if I'm understanding it right
On host side, both players are Dynamic and on client side both players are Kinematic
Yes. That is what you want. You probably will still get pushing and/or bouncing. But that is how things should be set up to start.
If you are using network rigidbody with server auth network transform, that is what you will get
You could also just make them kinematic everywhere. Because for what you want (no bouncing, no pushing) you're going to have to manually detect collisions between players regardless I think.
It just depends if you need the rigidbody to be dynamic for collisions with other objects or not.
I was just thinking about detecting players with a Raycast and cancel movement if I'm close to a player
If nothing is ever gonna move with physics then you might not need rigidbodies at all. Just have static colliders
Yeah. Plenty of ways to do that. Raycast, SphereCast, SweepTest, etc.
Sorry if I'm being annoying, I'm having a hard time with correcting this issue
I also considered it but it implies that all collision detection (including map) should be made with raycasts
Yeah. I think you'll want to keep them as is with what we've currently landed on. All dynamic on server side, all kinematic on the client side and manually stop collisions before they happen between players using some sort of cast or sweep test.
I tried to make the player movement stop if the player was close to another player but I had no way to make the player able to go in other directions
It was simply blocked
Yeah. Raycasting would fix that. You can put your player objects on a specific layer and only perform the raycast on that layer.