Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!