- Home /
Question by
Jenifer_Jane · Oct 15, 2020 at 05:18 PM ·
2drotation3dquaternionprogramming
need help regarding rotating arm
hello guys/girls
i am trying to implement 360 aim with a 3d model in 2d world (Unity Engine) so far its working only when character is facing right when i rotate my character to face it left (-90 degree) . character's arm looking at mouse position until character face left 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);
}
Comment