Привет.
У меня есть скрипт лука
`using UnityEngine;
public class Bow : MonoBehaviour
{
public GameObject arrowPrefab;
public float launchForce;
public Transform shotPoint;
public Transform bow;
public int damage;
public float range;
public float timeBtwShots;
private float nextTimeToShoot;
private GameObject curTarget;
private void Start()
{
}
void Update()
{
nextTimeToShoot += Time.deltaTime;
if (curTarget != null)
{
Vector2 relative = curTarget.transform.position - bow.position;
float angle = Mathf.Atan2(relative.y, relative.x) * Mathf.Rad2Deg;
Vector3 rotation = new Vector3(0, 0, angle);
bow.localRotation = Quaternion.Euler(rotation);
}
if (nextTimeToShoot >= timeBtwShots)
{
if (curTarget != null)
{
nextTimeToShoot = 0;
Shoot();
}
}
UpdateNearestEnemy();
}
public void Shoot()
{
if (curTarget != null)
{
Enemy enemyScript = curTarget.GetComponent<Enemy>();
enemyScript.TakeDamage(damage);
}
GameObject newArrow = Instantiate(arrowPrefab, shotPoint.position, shotPoint.rotation);
newArrow.GetComponent<Rigidbody2D>().velocity = transform.right * launchForce;
}
private void UpdateNearestEnemy()
{
GameObject currentNearestEnemy = null;
float distance = Mathf.Infinity;
foreach (GameObject enemy in Game.enemies)
{
if (enemy != null)
{
float _distance = (transform.position - enemy.transform.position).magnitude;
if (_distance < distance)
{
distance = _distance;
currentNearestEnemy = enemy;
}
}
}
if (distance <= range)
{
curTarget = currentNearestEnemy;
}
else
{
curTarget = null;
}
}
}`
При выстреле из лука стрела летит просто в врага, а мне хотелось бы сделать ее траекторию так, чтобы при выстреле стрела летела вверх и приземлялась во врага.
Никак не могу понять что нужно добавить в скрипт, дабы получилась моя задумка. Буду рад любым ответам и решениям.