I’m in the process of doing a 2d platformer engine and as part of that project I needed a good 2d camera system. I was encouraged by some fellow indie developers to make it a full featured asset that could be put up on the asset store for others to enjoy, so while I make progress on the system as documented here, I wanted to solicit some feedback from any would be users of such a 2d camera. What sorts of features would you like to see in a 2d camera that’s ideal for your game? So far my feature set list contains:
Areas that are blocked off via colliders
Room based camera movement (camera moves when hitting the edge as see in the Zelda series)
Multiple target focusing, camera points to the mid-point of the group
Dynamic zooming for multiple targets when they move too far apart to all be on the screen
Lookahead / lookbehind values
Momentary “reveal” targets that pan the camera to the target for a moment and then return
Ability to work on any of the XY / XZ / YZ axes
I’ll have a few web player demos up soon to show these modes.
Yes you set up triggers and then put a script on the GameObject declaring in which directions that collider should be counted as blocking the camera. If you leave the script off, the collider is considered to be blocking all directions.
I am prototyping a top-down game for tablets, so I could use a camera with some extra features, such as:
Ability to zoom the view in/out (with limits) when player does the traditional 2-finger “picture resize” pinching.
I’m thinking I would like to allow the player to touch and drag on their avatar such that the camera view is offset. In other words, reposition the camera’s view of the avatar such that the avatar isn’t in the exact center of the screen (again, with limits).
I will add a task to make zooming a function of the camera system. There will be a method you can call when you process a pinch/expand gesture to set the zoom value between a minimum and maximum that you’ve defined.
When you say you can touch and drag on their avatar and have the camera view offset, do you mean that the camera will “look ahead” in the direction the player is facing or moving? If so that feature is what I was referencing above with the “Lookahead / lookbehind values” item so that will definitely be in.
For the offset, I wasn’t specifically referring to “look ahead” (though that would be a good camera option). The “ship” the character will be piloting in my game will actually be rather large, so I am considering allowing the player to drag his view of it to the sides/top/bottom to better see what’s around them. The size of the ship is also why I’m interested in the zoom capability (and maybe that will be enough).
Conceptually, it’s like the ship is a child of the camera: you touch and drag to give it an offset. The trick is this doesn’t change the ship’s position in environment, so you’re actually moving the camera.
For actually implementing it (just brainstorming here), I imagine it could be set up that if the player touches the ship center and drags one direction, the camera actually moves the other direction. This would give the illusion of dragging the ship off the center of the camera’s view. Probably a tap on the ship center would cause the camera to return to the center point.
If you could add this functionality, that would be great - but I certainly understand if it’s not something most people will need!
Yes I’ve seen that review, it is very excellent. That particular video has a lot of very specific functionality relating to a platformer camera system. I will eventually have the same sort of “platform lock” abilities that are shown in the video, but I won’t have that ready for the first release of this camera system. My intention was to add on more specific capabilities, like those needed by a platformer, as I develop those systems and have really good test cases. I’m hoping the camera I have here can create all the specifics seen in that video without the need to change much as I think most of what’s shown in that video is a matter of decoupling the desired location for the camera from the player, which is quite trivial currently.
Could you accomplish what you’re describing by having the camera target track a GameObject that’s not the player but is positioned relative to the player based on the mouse position? This GameObject would of course be restricted in the distance it could move from the center of the ship, as if attached by a string. That plus zoom sounds like it would get you what you want.
Another video from Dave Fleming (@Ultima2876) on Twitter. This one is on Insanely Twisted Shadow Planet’s camera. The current camera supports all of what’s in that video except the nice soft ease-out when arriving at the target. I’m going to put in a new section for the demo showing off the “point of interest camera” type effect though.
I think my case is a little trickier because I’m going for a touchscreen interface. In my previous suggestion, I began by assuming the ship would have a camera target as a child, and dragging on the ship would offset that child. Then I thought I’d “cut out the middle-man” by just making the camera a child of the ship.
But maybe it’s better to not have the camera be a child of the ship, because techniques like panning the camera away to show the player something will probably be easier if the camera is not directly linked to the ship in the hierarchy.
So as I’ve been discussing various needs with people it seems that most of the game specific bits are all wrapped up in how the camera’s target moves. So I’m going to concentrate on doing some helper scripts to move the camera target around in a similar fashion to what ISTP is doing. I have a few things like that now, but I think it’s worth doing a slightly more comprehensive set of helper scripts to accomplish a few common control schemes such as a twin stick shooter, a top-down or side view racing game, and eventually lots of helpers to make a Super Mario World level of control over the camera.
For your zooming, are you going to zoom a discreet amount (actual world distance if perspective, camera size if ortho) or would you want to zoom a percentage of your initial zoom?
That’s a good question. I’ve been prototyping the 2D game I mentioned above, and am using a perspective camera looking down on the xz plane (in which the game play takes place). I’m working on the assumption that I would base the camera zoom positions in relation to that game plane (maybe by getting the distance of a ray cast from the camera to that plane, if the camera is slightly angled).
Zooming in terms of percentages seems like the most robust, since it would (in theory?) be more removed from the actual scale of the scene than discreet amounts.
But I have a feeling that either case will be fine, and involve some trial-and-error.
There are still a few bits to be added but I’m basically ready to call it good on a 1.0 version for the Asset Store which I’ll be submitting tomorrow. I’ll continue to respond to feature requests and of course fix bugs that are discovered over the next few weeks but if there’s some important bit missing for your use case, please chime in here.
Also tomorrow I’ll be recording a video showing off how you can tweak various parameters to get different effects.
things i noticed:
-is vsync enabled? there is a hickup for me every once in a while
-zooming out on your multiple-camera-target-mode jitters a bit. A wild guess would be that you check the positions on the screen AFTER you modify the size(orthogonal zoom) of the camera (making the camera using the values of last frame) while the camera-position is modified in LateUpdate, but i am not sure about that
–you can get rid of that completely, try LateUpdate when applying the ortho-size, i assume you are doing it already for the player-follow which is perfectly smooth.
-nice lava background. is it procedural :F ?
-i think zooming in percentage is much nicer, the discreet zoom may only be worthwhile in a fully block-environment when you want a specific amount of block in the viewport
-you can also go for hybrid and clamp the zoom to specific values, e.g {20, 24, 29, 35…} blocks of orthogonal size
-i used procentual zoom in my little game if you want to try it out (mousewheel zooms manually)
When panning to an object of interest (and back), the camera doesn’t move directly to the target point, instead it seems to move the same speed vertically as horizontally, and you inevitably hit the end of movement for one before the other. Maybe that’s intended, and for some cases even desired, but I would like to also be able to move in a direct line to the target point.
The point-of-interest focusing, while really cool, seemed a bit jerky. Maybe related to what Marrt was talking about above?
I really like the multi-target focusing, but the transition when returning to just the player seemed like it could be smoother(?).
Nevertheless, there are some really cool things going on here.