Forum rules - please read before posting.

GameCamera Constrain on Z Axis Question

Hello,

I'm running into a bit of a snag with a GameCamera - below I'll layout what I'm trying to do and will include a video link as well as links to all ActionLists and the custom script:

In a 3D Project I am using a GameCamera with the Movement Method set to: Direct

In the game the player is looking through a telescope, so the GameCamera is set to following the cursor. At some points in the game I am wanting to force the camera to pan over to certain events - and with that I am using a custom script (link below will have these components shown). X,Y,Z Axis Movement, Spin and Pitch Rotation, and Field of View are all Locked.

When I want the camera to automatically pan to something, using an ActionList I call LookAtTarget() from my custom script 'ScopeFocusOnTarget'.

This works splendidly as the camera smoothly focuses on the target. Then, when I want to give control back to the player, I call StopLookAtTarget() from the same script via an ActionList - this is where I am getting some undesired results.

Control does revert back to the player, yet the Z rotation is now enabled (previously is was not), and this leads to the camera getting lopsided (as seen in the video).

I tried using gameCamera.lockZLocAxis and a couple other restraining commands I found in the scripting guide, but I can't get it to lock correctly.

I confirmed that before focusing on a target, the MainCamera's z rotation does not spin - but after using gameCamera.SwitchTarget() to focus on the target, then going back to FollowCursor, the MainCamera's z rotation is now unlocked.

I hope I explained that well enough, here are the components and the script: https://imgur.com/a/tuy4ENa

Thank you in advance for any assistance!

Comments

  • Oh:

    Unity version: 2021.3.2f1
    AC version: 1.80.1

  • lockZLocAxis refers to its Z-axis position, not rotation. I'm not sure why you'd be getting a shift in Z-rotation, but it could be something to do with the use of LookRotation and the camera's starting rotation.

    Try forcing the camera Transform's Z euler angle to zero when reverting, but in general I'd say the way to approach this behaviour would be to rely on separate cameras for the different targets, which you can then switch between as normal using the Camera: Switch Action.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.