У меня есть стены из тайлмапов и на них висит коллайдер для тайлов, но иногда пуля пролетает сквозь коллайдер и не могу понять в чем дело, в движение пули или в настройках тайлов
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D), typeof(Collider2D))]
public class Bullet : MonoBehaviour
{
[SerializeField] private float _speed = 5f;
[SerializeField] private int _damage = 10;
[SerializeField] private int _maxReflections = 5;
private Rigidbody2D _rigidbody;
private Vector2 _direction = Vector2.zero;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody2D>();
_rigidbody.isKinematic = true;
_rigidbody.useFullKinematicContacts = true;
}
public void Shoot(Vector2 direction)
{
_direction = direction.normalized;
}
private void FixedUpdate()
{
if (_direction == Vector2.zero) return;
var deltaMovement = _direction * _speed * Time.deltaTime;
_rigidbody.MovePosition(_rigidbody.position + deltaMovement);
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "WallDestroy")
{
Destroy();
}
if (other.gameObject.tag == "Verevka")
{
other.gameObject.GetComponent<DestroyVerevka>().destroyJoint2d();
}
var normal = other.GetContact(0).normal;
Reflect(normal);
}
private void Destroy()
{
CheckResult.instance.CheckBulletCount();
Destroy(gameObject);
}
private void Reflect(Vector2 normal)
{
if (_maxReflections - 1 == 0) Destroy();
_maxReflections--;
_direction = Vector3.Reflect(_direction, normal).normalized;
transform.rotation = Quaternion.LookRotation(Vector3.forward, _direction);
}
}