Вы используете жестко закодированные углы 10
и 345
независимо от направления, в котором вы смотрите.
Затем с помощью, например, laser02.right
всегда возвращает одно и то же Vector3
только то, что вы его отрицаете. Это приводит к неправильному направлению. Это направление, которое вы получите, если сравнить изображения.
То, что вам больше всего нужно, это отрицать угол, на который вы поворачивали пули.
private IEnumerator FireContinuously()
{
while (true)
{
var laser02 = Instantiate(bullet01, firePoint2.position, Quaternion.Euler(new Vector3(0, 0, 10 * direction)));
laser02.GetComponent<Rigidbody2D>().velocity = laser02.transform.right * projectileSpeed * direction;
var laser03 = Instantiate(bullet02, firePoint.position, Quaternion.Identity)
laser03.GetComponent<Rigidbody2D>().velocity = laser03.transform.right * projectileSpeed * direction;
var laser04 = Instantiate(bullet03, firePoint3.position, Quaternion.Euler(new Vector3(0, 0, 345 * direction)));
laser04.GetComponent<Rigidbody2D>().velocity = laser04.transform.right * projectileSpeed * direction;
yield return new WaitForSeconds(projectileFiringPeriod);
}
}
И небольшой намек:
Если вы предпочитаете делать свои префабы типа
[SerializeField] private RigidBody2D bullet01;
[SerializeField] private RigidBody2D bullet02;
[SerializeField] private RigidBody2D bullet03;
тогда Instantiate
будет напрямую возвращать соответствующую ссылку RigidBody2D
, и вы сможете избавиться от GetComponent
вызовов:
private IEnumerator FireContinuously()
{
while (true)
{
var laser02 = Instantiate(bullet01, firePoint2.position, Quaternion.Euler(new Vector3(0, 0, 10 * direction)));
laser02.velocity = laser02.transform.right * projectileSpeed * direction;
var laser03 = Instantiate(bullet02, firePoint.position, Quaternion.Identity)
laser03.velocity = laser03.transform.right * projectileSpeed * direction;
var laser04 = Instantiate(bullet03, firePoint3.position, Quaternion.Euler(new Vector3(0, 0, 345 * direction)));
laser04.velocity = laser04.transform.right * projectileSpeed * direction;
yield return new WaitForSeconds(projectileFiringPeriod);
}
}