Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

need help regarding rotating arm

ms07ms07 Member
edited October 2020 in Programming

hello guys/girls


i am trying to implement 360 aim with a 3d model in 2d world so far its working only when character is facing right when i rotate my character to face it left (-90 degree) aiming arm face opposite direction instead looking at mouse pointer ..... i tried flipping angles direction multiplying by 1 and -1 but its working in reverse instead. here's code i am using for arm rotation.


  [SerializeField] Transform armToRotate;

 // arm rotation fixer

  [SerializeField] float mod;


void Update()

{

 lookAtPos = Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition);


    LookAtMouse();

}


 void LookAtMouse()

  {

    if (bodyToRotate.rotation.eulerAngles.y == 90f)

    {

      mod = 1;

      print("90");

    }


    if (bodyToRotate.rotation.eulerAngles.y != 90f)

    {

      print("-90zzz");

      mod = -1;



      armToRotate.localEulerAngles = Vector3.zero; // added just maye previous rotaion is bugging new rotations (honestly no idea)


    }



    armToRotate.localEulerAngles = Vector3.zero; // added just maye previous rotaion is bugging new rotations (honestly no idea)


    Vector2 lookDir = lookAtPos - armToRotate.position;

    float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg * mod;

    armToRotate.localEulerAngles = new Vector3(angle, 0f, 0f);

  }

Sign In or Register to comment.