Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda