- Home /
Dynamic camera for a side scroller
How can would I code a camera normally following the player the game, but at certain areas or during certain attacks have the camera switch to a more dynamic view of the player or slow down while dynamically looking at the player then switch back to normal view (as in super street fighter 4).
-would I use triggers that the player would run into (then how would I do the certain attack dynamic views)...
-would I script that when a certain event or animation is triggered...
-would I just set up a camera track (if so then how) that the camera would follow the movements...
Thanks
Answer by · Sep 03, 2010 at 08:03 AM
I would suggest that you decide on (and create) the desired effect, and then worry about how and where you want to integrate it. Depending on the gameplay, more than one of your own suggestions could be valid, and then having the camera event code in its own bundle would make it easier to trigger at the appropriate times (whether by entering an area, or when playing a specific animation/combo).
To create animated cameras, you'd probably be best animating it in Maya (or similar 3D program), and playing the animation on an object, which a new camera is parented to (as described in this answer). This approach would make it much easier to sync with the character animations.
If you're after dynamic viewpoints when you enter an area, you could:
- Create a GameObject with a Collider and isTrigger as True
- Create a script with a Vector3 and attach to the GameObject
- Store the desired camera position for that trigger area to the Vector3 in the script
- OnTriggerEnter, inform the CameraManager/script that it has changed state, and should track from the new position (specified on that GameObject). You could also specify whether to blend or cut.
- OnTriggerExit, inform the CameraManager/script that the special state has ended, and it should return to standard tracking.
For slow motion effects, use Time.timeScale. This directly controls the scale at which time passes.
If you're inexperienced with scripting/coding, there are plenty of resources to get you started - take a look at 'How can I start learning Unity fast? (List Of Tutorials)'. For the gameplay you've described, I'd suggest you start with the 2D Gameplay Tutorial.
By the sounds of things, you don't have very much scripted yet. You should try to get a side-scrolling character and camera before worrying too much about dynamic effects. If you get stuck, search the wiki as there are a lot of posts regarding 2D gameplay and cameras.
Hopefully this will give you a decent idea of where to work towards!
Thanks man... so 1. what would an example of that bundle look like in script, I'm not a programmer but I do know how to write code. Say in my LookAt script (thats attached to the camera) I could write when Trigger A is hit, call XYZ script. Then in XYZ script i would write $$anonymous$$ainCamera translate "this way and that way, zoom in zoom out" then back to original position? and 2. The Camera$$anonymous$$anager sounds pretty proficient. It sounds like the CameraDirector in Unreal's $$anonymous$$atinee. Do you have an example of what that looks like? I'm sorry I'm so picky, I don't expect you to give me a complete code, Thanks
I think it'd be a lot easier to animate the camera movement than to try to script it with code. You can animate in $$anonymous$$aya (for example) and play that animation on a camera in Unity - see http://answers.unity3d.com/questions/8537/camera-animations-in-maya. I may have misconstrued what I meant by Camera$$anonymous$$anager... I just meant an empty GameObject where all the camera-specific scripts were kept (if you wanted to switch between cameras, rather than only using the Camera.main).
I'll update my answer with a few more suggestions.
I've just realised that you may not specifically be talking about animated cameras - just moving the camera to a new position and slowing down the game?
Hmm, is that not the same... Thanks for the awesome answer by the way, but yeah just simple personality to the camera. Like as $$anonymous$$ute as a camera shake.
Ah right. I think I got the idea of dynamic camera zones/animations stuck in my head, from when you mentioned SFIV. Eric5h5's linked to a camera shake script before: http://answers.unity3d.com/questions/19559/is-it-possible-to-shake-the-camera.