- Home /
Question by
zeynolladamir123 · Jan 09, 2021 at 11:02 PM ·
collisioncollidermultiplayerphotonpun
Collision doesnt work for big distances
Hi ! I am making multiplayer shooter 2d game by photon.But for big distances collider doesn't detect collision when bullet of player number1 shoot player number2,i use OnTriggerEnter2D for bullet and player prefabs.Have any suggestions?Thank you anyway!
Here is my part of code from player script:
public void OnTriggerEnter2D(Collider2D collision) {
if (collision.CompareTag("Bullet")) {
if (!collision.GetComponent<PhotonView>().IsMine) {
if (NameOnPlayer.clor == collision.GetComponent<SpriteRenderer>().color) {
PhotonNetwork.Destroy(this.gameObject);
res = true;
}
}
}
}
}
and bullet script:
public class bullet : MonoBehaviourPun {
public void OnTriggerEnter2D(Collider2D collision) {
if (collision.CompareTag("Player")) {
if (!collision.GetComponent<PhotonView>().IsMine) {
PhotonNetwork.Destroy(this.gameObject);
}
}
if (collision.CompareTag("wall")) { PhotonNetwork.Destroy(this.gameObject); }
}
}
Comment
Answer by logicandchaos · Jan 10, 2021 at 12:58 PM
The bullets are probably moving too fast. Using raycast collisions will fix it, or you could try using continuous collision detection I believe.. there are different settings, but using raycasting is probably the best option.