I am trying to code a basic version of a game be and my friends are making.
the problem is that when the player shoots a bullet when moving the bullet will either hit the player and disappear (If Istrigger on the bullet box collider is ticked) OR (If Istrigger is not ticked) the bullet will stop moving when they touch the environment.
I have a collision ignore script to stop the bullet from hitting my player
Bullet script
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 20f;
public Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb.velocity = transform.right * speed;
}
void OnTriggerEnter2D(Collider2D hitInfo)
{
Debug.Log(hitInfo.name);
Destroy(gameObject);
}
}
Ignore Scrip
using UnityEngine;
using System.Collections;
public class ignore : MonoBehaviour
{
public GameObject playercollision;
public GameObject bulletcollision;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
Physics2D.IgnoreCollision(playercollision.GetComponent<Collider2D>(), bulletcollision.GetComponent<Collider2D>());
}
}