Jump to content
  • Advertisement
DrMeowEyes

Using Lerp For Camera Movement Smoothing. Help!?

Recommended Posts

Hello Everyone of the Angelscript Forum,

I am back with yet another weird situation. I am sure you guys know the answer to this one. I am baffled right now. 😀

So, I am trying to get a camera in a 2D game follow the player with smooth movement. I got the camera following with smooth movement part working, but the problem I have now is that the player character is at the top left corner of the screen. I cannot seem to get the camera to center the player to the screen. I am not sure what to do. The camera smoothing part is working! How do I get the camera to be over the player character so he is near the center of the screen?

Here is my code:
 

float time = UnitsPerSecond(10.0f);
float lerp = 0.1f;

 vector2 position = GetCameraPos(); <- I think this is a problem because to center the camera on player, I would need this to say "vector2 position = PlayerPos - ScreenSize / 2". But if I use that code with PlayerPos - ScreenSize/2 the camera becomes jittery, but I dont understand why that happens?
 
 position.x = position.x + (player.x - position.x) * lerp * time;
 position.y = position.y + (player.y - position.y) * lerp * time;
 print(position.x);
 SetCameraPos(position);

 

Anyone have an idea on what im doing wrong here?

Thank you,

DrMeowEyes

Share this post


Link to post
Share on other sites
Advertisement

I figured it out! I just had to make a slight change from this...

position.x = position.x + (player.x - position.x) * lerp * time;
 position.y = position.y + (player.y - position.y) * lerp * time;

to this...

 position.x = position.x + (player.x - (position.x + GetScreenSize().x/2)) * lerp * time;
 position.y = position.y + (player.y - (position.y + GetScreenSize().y/2)) * lerp * time;

Share this post


Link to post
Share on other sites

I'm glad you solved it, but I'm not sure the original question was very relevant to Angelscript itself? It's more related to the engine you're using that implements Angelscript.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!