ITprogER76
@ITprogER76
Просто человек.

Как создать баллистику при стрельбе raycast?

В реальной жизни, когда стреляешь из оружия на большом расстоянии, пуля в полёте со временем начинает слабеть и падать вниз по определённой траектории. Вот мне нужно как-то сделать баллистику при стрельбе, созданной через raycast. Помогите пожалуйста! Как можно это реализовать?
Скрипт стрельбы:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RifleB : MonoBehaviour {

    private RecoilController recoilController;
    private Camera _camera;
    public GameObject body;
    public float minx = -5;
    public float maxx = 5;
    public float miny = -5;
    public float maxy = 5;

    void Awake()
    {
        recoilController = body.GetComponent<RecoilController>();
    }
    void Start()
    {
        _camera = GetComponent<Camera>();
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Shoot();
        }
    }
    public void Shoot()
    {
        var currentRotate = transform.rotation;
        transform.Rotate(Random.Range(minx, maxx), Random.Range(miny, maxy), 0);
        Vector3 point = new Vector3(
        _camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
        Ray ray = _camera.ScreenPointToRay(point);
        transform.rotation = currentRotate;
        RaycastHit hit;
        recoilController.Recoil();

        if (Physics.Raycast(ray, out hit))
        {
            StartCoroutine(SphereIndicator(hit.point));
            transform.Rotate(0, 0, 0);
        }
    }
        private IEnumerator SphereIndicator(Vector3 pos)
        {
            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            sphere.transform.position = pos;
            yield return new WaitForSeconds(1);
            Destroy(sphere);
        }
    }
  • Вопрос задан
  • 474 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы