玩家翻转时物体未正确瞄准

问题描述 投票:0回答:0

当我的玩家和武器持有者(父级)翻转时,我的武器的 localScale 不会翻转。这是目前的代码,武器设置为始终瞄准鼠标,但翻转时却不会这样做

    //Get Mouse Position
    worldPos = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
    _direction = (worldPos - (Vector2)weapon.transform.parent.position).normalized;
    weapon.transform.parent.right = _direction;

    //Flip when aiming back
    angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg;

    Vector3 localScale = new Vector3(1, 1, 1);
    if (angle > 90 || angle < -90)
    {
        localScale.y = -1f;
    }
    else
    {
        localScale.x = 1f;
    }

    weapon.transform.localScale = localScale;

我尝试手动调整武器的 localScale,但这使它要么上下颠倒,要么仍然不面向鼠标

    //Get Mouse Position
    worldPos = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
    _direction = (worldPos - (Vector2)weapon.transform.parent.position).normalized;
    weapon.transform.parent.right = _direction;

    //Flip when aiming back
    angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg;

    Vector3 localScale = new Vector3(1, 1, 1);
    if (angle > 90 || angle < -90)
    {
        localScale.x = -1f;
        localScale.y = -1f;
    }
    else
    {
        localScale.x = 1f;
        localScale.y = 1f;
    }

    weapon.transform.localScale = localScale;
c# unity-game-engine 2d game-development
© www.soinside.com 2019 - 2024. All rights reserved.