Hi,
I've setup a Camera with Coordinates (0, 5, -10) and enabled lock-Y, follow Player character.
When I start the scene from the Editor it works as expected. Camera only follows Player on the X axis, Y stays put.
But when I enter the scene from another room the Y position got reset to 0.
I guess it is related to the Player not spawned in the scene when the Camera inits itself.
Any ideas for a hotfix?
Best.
Alex
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
In GameCamera.cs line 132
if (!haveSetOriginalPosition && backgroundConstraint && Camera.orthographic && (limitHorizontal || limitVertical) && Target) {
Transform.position = new Vector3 (0f, 0f, Transform.position.z);
}
I think it is a bug because it resets both x and y coordinate to zero.
It should make a distinction if limitHorizontal or limitVertical is false and only reset the respective axis.
I tried to fix it by only resetting the axis which is not locked. This works during gameplay. But when I save and load from another scene, the axis gets resetted again / camera works not properly.
Please help.
Could well be, though I'll need to recreate the original issue to confirm.
It sounds like you're using a Background Constraint to restrict the camera's movement - is this the case?
Please share your AC/Unity versions, as well as the full Inspector of the GameCamera.
Yes, Background Constraint is set. Camera is inside the constraint.
AC Version: v1.75.4
Unity: 2020.3.33f1
Screenshot of Camera: https://www.dropbox.com/s/udh8t2qzeq4pazu/Camera-Inspector-Screenshot 2022-10-18 110557.png
Thank you, I will look into this.
This may be similar to what you've corrected already, but here's a replacement for the GameCamera2D's ForceRecordOriginalPosition function:
I can't reproduce the issue of the camera resetting upon loading - but be sure to attach a Constant ID component to your camera. You should be seeing a Console warning about this not being present after loading.
Thanks Chris!
Constant ID did the trick for saving and loading!
Yes, your code is similar to mine. But I think you mixed up the resetting values in your script. When limitHorizontal is set then it should keep its x-position and not resets it to 0. Likewise with limitVertical.
Best.
Alex
When limitHorizontal is set, then the position is determined by the background constraint. The position in that direction needs to be zero'd, while the un-constrained axis should be unaffected.
Ah of course. I mixed it up sorry!
What I actually meant was not limitHorizontal/Vertical but lockHorizontal/Vertical.
I fixed it like this:
Understood, thanks.