#Collision response between players Rigidbody2D

1 messages · Page 1 of 1 (latest)

kindred skiff
#

Hi everyone, how can I prevent collision response between players (Netcode for GameObjects, server authority)?

sage jetty
#

Prevent it all together? Or prevent it for non-authoritative instances?

#

Simply using a NetworkRigidbody is all you need to do for the latter.

kindred skiff
#

Prevent il all together. Unfortunately, it is still happening when using NetworkRigidbody

sage jetty
#

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

kindred skiff
#

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

sage jetty
#

Ah, I see what you mean now.

gritty shale
#

Just make them kinematic

kindred skiff
#

Wait I might be dumb

#

Can I also prevent players pushing each other?

gritty shale
#

yea. Kinematic rigidbodies can only be moved through code. They have infinite mass so they won't be bumped around

kindred skiff
#

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

sage jetty
gritty shale
#

What version of NGO are you on? I think Network Rigidbody used to set the owner object as non kinematic automatically

kindred skiff
#

I'm using Rigidbody2D.MovePosition to move the player

_rb.MovePosition(_rb.position + movement * speed * Time.fixedDeltaTime);
sage jetty
#

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.

kindred skiff
#

I just tested it and the players can't collide with each other now

#

It looks like collisions between players are ignored

sage jetty
#

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.

gritty shale
#

Right, yea. movePosition ignores colliders. You'll need to AddForce()

kindred skiff
#

I'll give it a try

#

I'm struggling a bit, currently reading the doc

#

AddForce() is working only with a Dynamic RB

gritty shale
#

Local player will still need to be non-kinematic to move

sage jetty
#

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?

kindred skiff
#

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?

sage jetty
#

For player objects, most likely.

#

Unless they are moving extremely slow.

kindred skiff
#

So the Rigidbody shouldn't be server-authoritative then?

#

With server-authoritative, only the host's player has a Dynamic body type

sage jetty
#

Switching authority setups is irrelevant here. I'm just saying set the Collision Detection to Continuous.

kindred skiff
#

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

sage jetty
#

That means you're not fully set up for server auth then.

#

All of your players should be owned by the server.

kindred skiff
#

Sorry, I'm kinda new to Netcode, can you give me an example?

sage jetty
#

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

gritty shale
#

In the later versions of NGO, there is a checkbox on network rigidbody to prevent auto update to Kinematic

kindred skiff
kindred skiff
sage jetty
kindred skiff
#

I learned recently that runtime fee isn't a thing anymore

sage jetty
#

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.

kindred skiff
#

isKinematic = !IsServer should run only on the host's side if I understood correctly

sage jetty
#

It'll run on all sides. Just a different value for server vs client.

#

False for the server, true for all clients.

kindred skiff
#

So all clients will have a Kinematic body type?

sage jetty
#

Yes.

kindred skiff
#

On client side too?

sage jetty
#

Just on the client side.

kindred skiff
#

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

sage jetty
#

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.

gritty shale
#

If you are using network rigidbody with server auth network transform, that is what you will get

sage jetty
#

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.

kindred skiff
#

I was just thinking about detecting players with a Raycast and cancel movement if I'm close to a player

gritty shale
#

If nothing is ever gonna move with physics then you might not need rigidbodies at all. Just have static colliders

sage jetty
kindred skiff
#

Sorry if I'm being annoying, I'm having a hard time with correcting this issue

kindred skiff
sage jetty
#

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.

kindred skiff
#

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

sage jetty
#

Yeah. Raycasting would fix that. You can put your player objects on a specific layer and only perform the raycast on that layer.

kindred skiff
#

bool hit = Physics2D.Raycast(transform.position, movement, speed * Time.fixedDeltaTime, 3);

#

I'm thinking on a way to make movement possible in every other direction except the other player's direction