I'm currently refactoring.
I want my camera to follow a player, rather than being completely detached in third-person.
Goal: Allow a third-person camera while reserving the right to attach the camera to arbitrary objects.
What are some alternatives when constructing the player, camera, and game objects to allow this?
I currently have:
Input -> InputManager -> Camera => Modified Camera Position/Orientation
I've considered attaching the camera to an object (for instance, the player), and allowing the camera to modify the player position (since the camera receives the input). But this seems ludicrous!
Should the InputManager be provided with which object it should affect? And, if the camera happens to be attached to the affected object, that object is responsible for updating the position/orientation of the camera?
Input -> InputManager -> PlayerControlledObject -> Camera => Modified Camera Position/Orientation
Could anyone point me to a good example of how to do this, which allows for a good amount of flexibility in the future?
Thanks!
Using : JOGL 2.0
Camera, Player, and GameObject Architecture
If you are using component-entity architecture (not sure if you are since you didn't specify), you could just create a CameraComponent and attach it to any entity with a Transform (x, y, scale) component. This allows you to attach the camera to any entity.
Not sure, but it was the first thing that came to mind.
The way I would do it is every frame, get the camera to get the Transform component of the Entity it is attached to, and then, before you draw anything, push a Transform onto the stack, translate everything to that Transform location, THEN draw your stage, pop the Transform, and then draw your GUI or what have you.
The way I would do it is every frame, get the camera to get the Transform component of the Entity it is attached to, and then, before you draw anything, push a Transform onto the stack, translate everything to that Transform location, THEN draw your stage, pop the Transform, and then draw your GUI or what have you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement