- Home /
2D Top Down Camera Smoothing
Hello,
I have a camera that's a child of an object that I want it to follow (naturally), but when it comes to creating a smooth effect I am completely perplexed. Since the Camera is already following the object automatically how can I create a smooth effect without interfering with the transform component of the parent object? I've looked many threads and all the camera smoothing solutions seem to require a camera that's not coupled with the target. Does anyone have a solution for this?
Thank you.
Answer by wibble82 · Dec 07, 2015 at 04:30 PM
Hi
The simple fact is the correct solution is to not bind the camera rigidly to the object. This might initially seem the obvious approach - you want the camera to move with the object right?! But as you have discovered, as soon as you want subtly different behavior you're stuck.
Fortunately, it's not too difficult to make a camera that follows an object - you'll need to create a script for the camera that looks at its target object and works out where it wants to be each frame, then sets its transform accordingly.
Once you have that, the simplest way to achieve smoothing is to lerp towards your target position/orientation each frame. More advanced approaches exist that involve acceleration/deceleration, but lerps will be a good start.
Simple answer though - you need to decouple camera and object. Then all the camera smoothing examples on the internet will be helpful :)
-Chris
Hi Wibble, thanks for your answer.
I do understanding the LERPing mechanic but I made it so that each player (multiplayer game) has its own camera in the prefab spawn. I guess I'll have to try to uncouple that and make it so that it assigns the main camera to the local player or something.
Yeah it's annoying but is unfortunately the right way to go. I guess if you want to take the simplest path of taking your current system to the new system, you could:
Create a script to your camera (if you don't already have one)
Leave the camera as a child of the player in your prefab
Add a public member called 'player I am following'
In the start function of your player script, find the child camera, tell it about 'this' so it follows the correct player, then set its transform.parent to 'null', thus detatching it
That's perhaps not the most elegant approach, but is probably a nice simple way of converting your current system to a new one without writing loads of new code!
p.s. Your call if this is the 'right' answer, but if it is could you mark it as such - it means other people with similar questions will know its along the right lines!
Your answer
Follow this Question
Related Questions
Top-Down 2D game:How to make the camera move on hitting the sides of the screen? 2 Answers
2d top down Camera help 1 Answer
Any idea for smooth camera in pixel art sprite? 1 Answer
Camera looking down 1 Answer
Smooth Camera 2D Follow Player 0 Answers