Код: Выделить всё
private void Shoot()
{
_audio.Stop();
Ray ray = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
Vector3 targetPoint;
if (Physics.Raycast(ray, out hit))
targetPoint = hit.point;
else
targetPoint = ray.GetPoint(75);
Vector3 dirWithoutSpread = targetPoint - spawnBullet.position;
float x = Random.Range(-spread, spread);
float y = Random.Range(-spread, spread);
Vector3 dirWithSpread = dirWithoutSpread + new Vector3(x, y, 0);
GameObject currentBullet = Instantiate(bullet, spawnBullet.position, Quaternion.identity);
currentBullet.transform.forward = dirWithSpread.normalized;
currentBullet.GetComponent().AddForce(dirWithSpread.normalized * shootForce, ForceMode.Impulse);
_audio.time = 0.15f;
_audio.Play();
}
Мне это нужно, когда пуля физически соприкасается со стенками карты, на месте попадания остается след (изображение).
СЛЕДУЕТ ЧИТАТЬ КОНТАКТ ПРЕДМЕТОВ, А НЕ ЛУЧ
Моя карта состоит из множества объектов-стен и одного объекта-земли.
Скажите, пожалуйста, как это можно сделать?
Подробнее здесь: https://stackoverflow.com/questions/791 ... a-physical