admin管理员组

文章数量:1287527

Angle of rotation is completely off. If I add in values of -90,-270 ect, it rotates the sprite but its not how I want it to function. Input event for Look is added and functions as intended. The z axis values update as the mousePos is updated.

public void Look(InputAction.CallbackContext context)
{
    if (context.performed)
    {
        _mousePosition = context.ReadValue<Vector2>();
    }
}
private void RotateToMouse()
{
    Vector3 worldMousePosition = _mainCamera.ScreenToWorldPoint(_mousePosition);
    worldMousePosition.z = 0;
    Vector2 _direction = (worldMousePosition - transform.position).normalized;
    float angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg;
    transform.rotation = Quaternion.Euler(0, 0, angle);
}
private void UpdateAnimation()
{
    Vector3 worldMousePosition = _mainCamera.ScreenToWorldPoint(_mousePosition);
    worldMousePosition.z = 0;
    Vector2 _direction = (worldMousePosition - transform.position).normalized;
    _animator.SetFloat("InputX", _moveInput.x);
    _animator.SetFloat("InputY", _moveInput.y);
}

Trying to have the sprite look at the mouse position and rotate the correct direction when mouse moves position. The final aim is for the mouse to be the aim point for firing function.

本文标签: cUnity InputActionCallbackContextStack Overflow