Sign in to follow this  

Camera, Player, and GameObject Architecture

This topic is 1869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently refactoring.

I want my camera to follow a player, rather than being completely detached in third-person.

[b]Goal: [/b]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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Fabulous! This is my current approach. It seems sustainable. Is it common?
Much appreciated.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hey Neglected,
Thanks for your reply, the component method seems to be working very well for me!

Good insight, mate.

Share this post


Link to post
Share on other sites

This topic is 1869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this