#OnCollisionEnter2D dosent work

1 messages · Page 1 of 1 (latest)

edgy quarry
#

If the bullet also has a client network transform, they you have to SpawnWithOwnership()

hollow schooner
#

this is the code

    [ServerRpc]
    public void spawnBulletServerRpc()
    {
        GameObject spawnedObjectTransform = Instantiate(Bullet);
        spawnedObjectTransform.GetComponent<NetworkObject>().SpawnWithOwnership(0, true);
    }
edgy quarry
#

As in the bullet didn't spawn?

hollow schooner
#

it spawn and it movest

#

it dosent do anything on collision

#

i tried on trigger enter 2d and switchign the collider to a trigger and still dsoent work

#

bullet code

    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Entered Collision");
        if (collision.gameObject.tag == "Player")
        {
            Debug.Log("Entered Collision With Player");
            collision.gameObject.GetComponent<Player>().ChangeHealth(-10);
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("Entered Collision");
        if (collision.gameObject.tag == "Player")
        {
            Debug.Log("Entered Collision With Player");
            collision.gameObject.GetComponent<Player>().ChangeHealth(-10);
        }
    }
}
edgy quarry
#

If you are using NetworkRigidbody then make sure that both objects are owned by person, either the same clientID or both owned by the the Server
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/physics

hollow schooner
#

so then i just make it owned by the server and it shud work?

#

also i was testing with only the host so it shud have worked but it did not