#OnCollisionEnter2D dosent work
1 messages · Page 1 of 1 (latest)
If the bullet also has a client network transform, they you have to SpawnWithOwnership()
i did nothing happens still
this is the code
[ServerRpc]
public void spawnBulletServerRpc()
{
GameObject spawnedObjectTransform = Instantiate(Bullet);
spawnedObjectTransform.GetComponent<NetworkObject>().SpawnWithOwnership(0, true);
}
As in the bullet didn't spawn?
no the on collison script function didnt run
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);
}
}
}
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
There are many different ways to do physics in multiplayer games. Netcode for GameObjects (Netcode) has a built in approach which allows for server-authoritative physics where the physics simulation only runs on the server. To enable network physics, add a NetworkRigidbody component to your object.
well i need the bullet to be able to hit any player
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