ActionCameraPosition object

  1. We can add object in Unit with required position

  2. Add new property to ShootAction:
    [field: SerializeField] public Transform ActionCameraPosition { get; private set; }

  3. And CameraManager will looks like that:
    case ShootAction shootAction:
    _actionCamera.transform.parent = shootAction.ActionCameraPosition;
    _actionCamera.transform.localPosition = Vector3.zero;
    _actionCamera.transform.localRotation = Quaternion.identity;
    ShowActionCamera();
    break;


image

2 Likes

Yup that’s another great way to do it.
I probably wouldn’t change the parent, you might forget to unparent and if the Unit dies you could end up accidentally destroying the actionCamera.
So you could just set the actionCamera.transform.position = shootAction.ActionCameraPosition.position; and rotation

2 Likes

Actially setting a parent is a must.
I’ve ran into the weird camera behaviour and the reason is the order of position calculation: OnAnyActionStarted fired → set a position to ActionCamera.
But after you set this the Unit can still rotate to the target and the actionCamera.position is not valid anymore. So after OnAnyActionStarted you need to monitor the state (Aiming-Shooting) of the action and set it only after aiming is done or, much simpler, set a parent which will handle all of that and even make a cool effect of following Unit’s rotation while aiming.

Privacy & Terms