1
votes

I am building a survival horror like game and am hoping to make a very nice camera system to compliment the mechanics. Part of this is the fact that you will be able to crouch down and cover your face. The camera work I want to do with this is to zoom in to the character in order to constrain the view for the player as well.

The current MC structure that I have is:

GameMaster > Spawner (this is for the player and all enemies) > Player

The issue I'm having is that scaling the GameMaster (which is where side scrolling and other global game effects are happening) causes the centering of the camera to offset based on how far away the player is from 0,0.

You can see the issue clearly in this video. The red arrows point to the 0,0.

On this stackoverflow question the answer says to make a container for everything and center the containers 0,0 over the target that you want to zoom around. This poses a challenge for me because I would then have to get proper coordinates for an object nested 4 MC's in. I'm also unsure what that will then do for my current side scrolling camera.

Is there a way that I could mathematically figure out the offset when the character ducks? It seems like a viable option because you can't move until you let go of crouch and the camera zooms out.

If not, is the container MC a good option or is it just one of those "you gotta do what you gotta do." type situations?

[Added] I also see something about Transform Matrices or something. Is that something that would work? I know NOTHING about them but I assume they are CPU heavy and wouldn't be a good option for a mechanic prevalent throughout the whole game.

[Added 2] ALSO, I want to do a rotation camera effect that suffers from the same 0,0 issue. Blatantly showing up as the player and level rotating around some far off pivot point.

If a Transform Matrix can swiftly and functionally offset the 0,0 to the players location so that I can do all the camera effects and alterations. I think that may be the best way to go.

----Close to Conclusion---- In regards to Vespers answer. Would I then be able to tween the resulting transform? If so then that completely answers my entire problem. If not, I have no clue how to get the result I want.

1
Check this answer: Here - Vesper
Alright very cool. Now is it possible at all to tween the resulting transformation? - Gaian Swine Helmers
I expect that no, as this transformation is composed of three, in which the second one, not the last one, is the one you apparently want to tween. You can have a tween running unattached to an object, with required easing, and you then query its current value in your enterframe listener and create a new transform matrix using that value as current scale. - Vesper

1 Answers

0
votes

I think the container is the cleanest solution. Since it'll be centered on the player, rotations and scaling will work normally. You mention getting the coordinates for the nested MC is hard, but there is a built-in function to do exactly that: localToGlobal()

To get the player position in global coordinates, just do player.localToGlobal(new Point(0, 0)). This should return the Player's center in global coordinates. If your main container is not in global coordinates (because it's nested inside another transformed MC, for example), you can use the opposite function on the container to convert from global to local:

container.globalToLocal(player.localToGlobal(new Point(0, 0)))

Now you just need to center the container. That could also be used to simulate the camera movement. If you update the container position at every frame, it'll give the effect of the camera following the player.