My parent object components: Rigidbody2D and the script I shared below.
Children(Head, Body, Arm, Backpack...): There is only collider. There is no rigidbody2D. (I want the parent object to use the children's colliders, so I haven't add a rigidbody)
I want all my objects to rotate smoothly on their own axis. In the script below, it does not rotate on its own axis.
[SerializeField] public DynamicJoystick joystick;
public float speed;
Vector2 move;
public Rigidbody2D rb;
//Smoothly Turn
float _z;
float angle;
float turnSpeed = 15f;
void FixedUpdate()
{
move.x = joystick.Horizontal;
move.y = joystick.Vertical;
float x = joystick.Horizontal;
float y = joystick.Vertical;
angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
if (angle != 0)
{
_z = angle;
}
Quaternion rotate = Quaternion.AngleAxis(_z, Vector3.forward);
rb.transform.rotation = Quaternion.Slerp(rb.transform.rotation, rotate, turnSpeed * Time.fixedDeltaTime);
rb.MovePosition(rb.position + move * speed * Time.fixedDeltaTime);
}