Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
I'm getting a spin error, Can you help me fix this it?

I am working on a 2d zombie killing game but there was an error rotating the gun in my code, when I rotate the gun it turns wrong. Can you help me?

Video:https://youtu.be/8kUgXkEZc2M

Here is the code:

[SerializeField] Transform _arm;
    
float _offset = -90;

Vector3 _startingSize;
Vector3 _armStartingSize;

public GameObject Bullet;
public float BulletSpeed;
public Transform ShootPoint;

#region Start
// Start is called before the first frame update
void Start()
{
    _startingSize = transform.localScale;
    _armStartingSize = _arm.localScale;
}
#endregion

// Update is called once per frame
void Update()
{
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector3 perendicular = _arm.position - mousePos;
    Quaternion val = Quaternion.LookRotation(Vector3.forward, perendicular);
    val *= Quaternion.Euler(0, 0, _offset);
    _arm.rotation = val;

    if(transform.position.x - mousePos.x < -0.1)
    {
        transform.localScale = _startingSize;
        _arm.localScale = _armStartingSize;
    }
    else if(transform.position.x - mousePos.x > 0.1)
    {
        transform.localScale = new Vector3(-_startingSize.x, _startingSize.y, _startingSize.z);
        _arm.localScale = new Vector3(-_armStartingSize.x, -_armStartingSize.y, _armStartingSize.z);
    }

    if (Input.GetMouseButtonDown(0))
    {
        shoot();
    }
}

void shoot()
{
    cineShake.Instance.ShakeCamera(5f, .1f);
    GameObject BulletIns = Instantiate(Bullet, ShootPoint.position, ShootPoint.rotation);
    BulletIns.GetComponent<Rigidbody2D>().AddForce(BulletIns.transform.right * BulletSpeed);
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda