Forum rules - please read before posting.

Camera following character when constrains are applied - Camera switching

edited May 2018 in Technical Q&A
Hi guys, hi Chris. Aldo here, new to the forum and to Adventure Creator. Nice to meet you all.
I have a pretty easy set up where the character changes room without changing actual scene. I want a "going through the wall" effect, which would be pretty easy with just a "Teleport to marker" of the Character and the camera following. The problem is that the camera has a few constrains and can't follow it to the other room. So I'm opting for a "Camera Switch", I hope this is the best solution.

All works pretty fine, I'm happy with the animation, if it wasn't for a "glitch" that the camera does when jumping from NavCam1 to the original position of NavCam2 (video attached). I'm attaching the "Door: Go To" ActionList screenshot as well.

Is there a better way to do this? For example:
A - Easiest: Modify NavCam1 constrains on the fly, with the constrains I want for the second room (and vice-versa when going back);
B - Patch: Make NavCam2 start its route from NavCam1's latest position;

Thank you very much in advance!

Aldo


Comments

  • Welcome to the community, @AldoAndriani.

    You can certainly modify the camera's constraints at runtime.  The properties of the GameCamera that you can change in script can be found in the Scripting Guide here.

    Here's a sample script (ChangeCameraConstraints.cs) that you can place in your scene to switch between two sets of X and Z constraints:


    To use it, add it to a GameObject in your scene (even the camera itself), and fill in the Inspector fields.  Then use the Object: Call event Action to run its UseConstraintA / UseConstraintB methods when entering/exit the other room.
  • Amazing Chris! Thank you!
    I was actually using two scripts to control the camera (GameCamera and GameCamera2D), so with my poor coding skills I ended up with this version of your sample code:


    Now the animation is cool but pretty quick. Do you have any suggestions on how I can slow it down?



    Thank you!
  • At the moment the constraints are changed, the camera becomes "out-of-bounds", so moves to keep within them according to its Follow speed field (the dampSpeed float).

    A camera can be made to snap instantly to its "rest" position by calling its MoveCameraInstant() method - you may need to call that after changing its constraints.

    Also: is switching the player prefab necessary?  If all you're looking to do is move the player, you can use the Object: Teleport Action.
  • Off-topic, but also: if you're going for a retro/pixel aesthetic, consider checking the Retro-style movement option in your Player component for a less "floaty" feel.  See the "Retro movement" Manual chapter for more on what this does.
  • Thank you Chris! Implementing teleport and dampSpeed was exactly what was needed! Now the animation is smooth and seamless.
    I tried retro-style movement but it usually results in the player getting stuck at some corner of the Navigation mesh for a few seconds during the path.
  • Do they have a non-trigger collider attached?  That's not usually necessary with 2D games, and can result in such behaviour if your scene also has colliders.
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.