- Home /
How to follow a game object by camera but with a slower speed?
Hi everybody,
I have a problem. I do not want to drag a game object onto a camera so it is followed by the camera. I want to use script for camera and follow the game object by camera but with slower speed. It is actualy for 2D background scrolling. The camera follows my player so it is not moving always.
please help.
look to the many examples of, or just buy from the asset store, a "parallax" background. it's a standard thing for scrollers and you can easily find it
Yeah, I was already looking on it but all free assets and online tips on background scrolling works on arrow keys. That is not what I want because my player can walk and simultaneously stay on one spot so scrolling is then unnatural. I need to pair it with the camera which the only one follows my player...
you simply need to use a parallax scrolling background. and then decide, yourself, how you want it to move. for example if the "character animation of walking" makes the background move .. do that. from the animation just send a speed value to the parallax BG.
As I sayed, my player can walk and simultaneously stay on one spot because of barriers. In this case, the player IS walking but DOES NOT move. When I do what you are saying, my player will not move but the background will move.
I need to use a script attached to my camera with public variable and make my background moving accordingly to my camera only on X axis but with a slower speed lets say 5f. How should I do it?
So make it so that when your player collides with an object the walk animation finishes.
If the walk animation finishes then your background will stop moving.
Answer by sujit11dec · Mar 24, 2015 at 06:15 PM
One Simple Solution is, use smoothFollow script on camera.
For that firstly import "scripts" unitypackge in your scene.
Then on camera add smoothfollow script using Add Component.
Then in smoothfollow script, there is a Target field.
In Target feild, assign gameobject that you want to followed by camera.
Alter other options from the script to match your requirement.
Answer by Ericool · Mar 24, 2015 at 05:07 PM
the easiest thing would be to translate the camera with a script using a certain speed and a box collider with the player to stop moving if OnTriggerEnter .