i'm actually trying to make a sort 2d game with unity, in this game we control a character that can shoot bullets with a weapon. Actually an "Uzi", so it shoot very fast and hard,(so, a gun) the problem is, that sometimes, depending on the distance with the ennemy, the bullets go trough the box collider of the ennemy, and so don't touch it. I think it has to do with the Update/ Fixed update system of unity, but i'm not sure. and The bullets are already in collision detection Continuous. There is a part of the code, and screenshots.
void OnTriggerEnter2D(Collider2D target)
{
if (target.gameObject.tag == "FirePoint")
{
Fire();
}
if (target.gameObject.tag == "Building")
{
Destroy(gameObject);
//print("Don't shoot on the walls !");
}
Ennemy enemy = target.GetComponent<Ennemy>();
if (target.gameObject.tag == "Ennemi")
{
enemy.TakeDamage(damage);
Destroy(gameObject);
}
}
void Fire()
{
GetComponent<Rigidbody2D>().AddForce(transform.right * bulletForce);
}
and there is the method for shooting, in another script.
public void Shoot()
{
DispersionDesBalles();
nextFire = Time.time + 1f / fireRate;
Instantiate(Balle, spawnPoint.position, fireRotation);
ballesRestantes--;
}
and screenshots of the bug Here
The red rectangle are ennemies, and the little green things are bullets, don't pay attention to the graphics :D, It's just for testing.It's pretty annoying because in the game, the bullets are less spaced apart, but it amounts to the same thing.
I hope someone can help me. have a Nice day !