Action Camera shifting with multiple enmies

I have run into a strange bug when I shoot different enemies in the same turn. I am using the technique of a game object in the unit to specify the position the action camera is to take as well as using another student’s method of not using a switch in the CameraManager to set the camera but letting each action determine that.

So my CameraManager has

private void OnAnyActionStarted(object sender, EventArgs e) {
        if (sender is not BaseAction action) return;
        if (action.TrySetActionCamera(_actionCamera)) {
            ShowActionCamera();
        }
        
    }

and the ShootAction has

public override bool TrySetActionCamera(GameObject actionCamera) {
        var camPos = ActionCamPosition.position;
        var characterHeight = Vector3.up * camPos.y;
        actionCamera.transform.position = camPos;
        actionCamera.transform.LookAt(Target.position + characterHeight);
        
        return true;
    }

In my scene I have multiple enemies. On the same player unit when I shoot the first enemy the Action Camera sets the position of the game object in the unit as expected (in my case position: -0.5, 1.7, -1). However, if I then shoot another enemy the Acton Camera is placed at a different location (position: -1.1, 1.7, -0.2).

This repeats for any other enemy I target after that. The Action Camera is set to a different position each time.

Any idea of what is causing this?

It looks like from what I can see. You are resetting the action camera position everything you shoot an enemy. In your method TrySetActionCamera() what is calling that method and when?

Are you trying to have the camera change view to see different angles when you shoot multiple targets? What are you trying to have the Action Camera do specifically?

Privacy & Terms