1
votes

I'm making a 2D top-down game in LibGDX, using orthographic camera. The camera is supposed to follow player, rotate with him etc. I'm also using Box2D, which means every sprite is updated by model coordinates and angle. And I want to make the same with the camera.

This code:

Vector3 v = new Vector3(playerModel.getPosition().x, playerModel.getPosition().y, 0);
camera.rotateAround(v, Vector3.Z, -playerModel.getAngle() * MathUtils.radiansToDegrees);
camera.translate(deltaMove);
camera.update();

gives me only relative translation and rotation - relative to current position and angle of the camera. And although this works I don't think It's the best, is it?:

Vector3 v = new Vector3(playerModel.getPosition().x, playerModel.getPosition().y, 0);
camera.up.x = (float) Math.cos(playerModel.getAngle());
camera.up.y = (float) Math.sin(playerModel.getAngle());
camera.position.x = v.x;
camera.position.y = v.y;
camera.update();

Is it possible to do it smoother way with orthographic camera or should I use a classis 3D camera?

1
You set the position and angle perfectly synced with the player. How do you want it more smooth?noone
Why aren't there any setters for it? I can't even change camera.position vector (because it's final) only its properties, so I thought that it's not the proper way to set the camera. Nevermind :)chriemmy
I don't know why exactly it is like this. You can still use camera.position.set(...) which does basically the same as a camera.setPosition(...) would do. I guess it's because like this it reduces the amount of new Vectors being built and it saves one method call, which might make a difference on mobile devices.noone

1 Answers

0
votes

You can remove the jerky movements of the camera by interpolating the current frame's camera properties between the last camera properties and the new camera properties. Camera movements are very jerky if you don't use some kind of interpolation.

I hope this helps, I would go into how to implement such such a change, but it seems a bit beyond the scope of this question.