Weapon rotation animations move firePoint in mouse position

Viewed 22

My weapon has animations corresponding its direction to the mouse (left, right, up-right, down, etc.). The problem is when I move the mouse the firePoint gameObject is moving at mouse position, which can cause the gun to shoot in a direction that does not correspond its direction of animation. Here you can see what happens The code is used to display the correct animation using animation Blend Tree.

void UpdateAnimation()
{
    Vector3 mouseLocationWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
    mouseLocationWorld.Normalize();
    if (mouseLocationWorld.x == 0f && mouseLocationWorld.y == 0f)
    {
        _animator.SetFloat("LastHorizontal", mouseLocationWorld.x);
        _animator.SetFloat("LastVertical", mouseLocationWorld.y);
    }
    else
    {
        lastX = mouseLocationWorld.x;
        lastY = mouseLocationWorld.y;
    }
    _animator.SetFloat("Horizontal", mouseLocationWorld.x);
    _animator.SetFloat("Vertical", mouseLocationWorld.y);
}
0 Answers
Related