- Home /
2d camera help!
Hi
I'm trying to create a javascript that would make the camera partially follow the mouse, but mainly the player in my 2d sidescroller! (And its movement should also be smoothed) I need help with it! Any advice will help and be appreciated! Thank you in Advance :)
Does this not sound like a question more appropriate for the forum, to you?
If you want the camera to follow at the player, just search "Smooth follow" in the project panel and drag that onto your camera and drag the player in the empty slot in the inspector.
Answer by The-Oddler · Mar 18, 2011 at 03:23 PM
You could probably use Mathf.lerp for this. Just get the mouse x and y, and your characters x and y and lerp somewhere between it.
Some pseudo code:
camX = Mathf.lerp(characterX, mouseX, .3f);
camY = Mathf.lerp(characterY, mouseY, .3f);
Camera.SetPosition(camX, camY);
Something like that should work, you can change the .3f to something else (1.0f would mean your camera would look where your mouse is, and 0.0f would mean looking directly at the character, .5f is right in the middle ;) )
Hope this helps,
-The Oddler
Your answer
Follow this Question
Related Questions
Making the players head face toward the location of the mouse? 1 Answer
How do I get the camera to follow my character? 2 Answers
The sprite that is being followed by thr camera is very jittery and doesn't look very nice at all. 2 Answers
Sidescroller Bullets Follow Mouse After Being Shot 2 Answers
Problems with 2D Camera Shaking 3 Answers