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
版权声明:本文标题:c# - Unity InputAction.CallbackContext - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741304590a2371292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论