Персонаж не стреляет влево unity2d

Всем привет. Делаю игру, похожую на soul knight. Управление оружием и персонажем реализовано по одному джойстику, как и в референсе. Встретил проблему: если персонаж смотрит направо, стрельба работает как надо, а если повернуться налево, то

  1. shotPoint(место вылета пуль из оружия) не флипается как оружие, т. е слева оружие как будто перевёрнуто вверх тормашками, хотя это не так
  2. Пули не летят, но создаются на сцене, видимо, разбиваются обо что-то

Код Player.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public Joystick joystick;
    public float speed;

    private Rigidbody2D rb;
    private Vector2 moveInput; // Считывает в которую сторону движется перс
    private Vector2 moveVelocity; // Итоговая скросоть игрока в направлении
    private Animator anim;

    private bool facingRight = true;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent < Rigidbody2D>();
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        moveInput = new Vector2(joystick.Horizontal, joystick.Vertical); // Считывает вертикальное и горизонтальное движение
        moveVelocity = moveInput.normalized * speed; // конечная скорость

        if (moveInput.x == 0)
        {
            anim.SetBool("isRunning", false);
        }
        else
        {
            anim.SetBool("isRunning", true);
        }

        if(!facingRight && moveInput.x > 0)
        {
            Flip();
        }
        else if(facingRight && moveInput.x < 0)
        {
            Flip();
        }
    }


    void FixedUpdate()
    {
        rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime); // двигает игрока
    }

    public void Flip()
    {
        facingRight = !facingRight;
        transform.Rotate(0f, 180f, 0f);
    }
}

Gun.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Gun : MonoBehaviour
{
    public Joystick joystick;
    public float offset;

    public float rotZ;
    private SpriteRenderer spriteRender;
    public GameObject bullet;
    public Transform shotPoint; // место, откуда будет вылетать пуля
    private float timeBtwShots; // время между выстрелами
    public float startTimeBtwShots;
    private Player player;

    // Start is called before the first frame update
    void Start()
    {
        spriteRender = GetComponent<SpriteRenderer>();
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Mathf.Abs(joystick.Horizontal) > 0.001f || Mathf.Abs(joystick.Vertical) > 0.001f)
        {
            rotZ = Mathf.Atan2(joystick.Vertical, joystick.Horizontal) * Mathf.Rad2Deg;
        }

        transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);

        if (rotZ < 90 && rotZ > -90) // поворот оружия
        {
            spriteRender.flipY = false;
        }
        else
        {
            spriteRender.flipY = true;

        }


        if (timeBtwShots <= 0)
        {
            if (joystick.Horizontal != 0 || joystick.Vertical != 0)
            {
                ShootButton();
            }
        }
        else
        {
            timeBtwShots -= Time.deltaTime;
        }
    }

    public void ShootButton()
    {
        Instantiate(bullet, shotPoint.position, transform.rotation);
        timeBtwShots = startTimeBtwShots;
    }
}

Bullet.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public float speed;
    public float lifetime;
    public float distance;
    public int damage;
    public LayerMask whatIsSolid; // что будет пробивать


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance, whatIsSolid);
        if (hitInfo.collider != null)
        {
            if (hitInfo.collider.CompareTag("Enemy"))
            {
                hitInfo.collider.GetComponent<Enemy>().TakeDamage(damage);
            }
            Destroy(gameObject);
        }

        transform.Translate(Vector2.right * speed * Time.deltaTime);
    }
}

Подскажите, пожалуйста, что я делаю не так. Еще зачем-то сразу после запуска пуля пролетает, но не из оружия


Ответы (0 шт):