Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera, Player, and GameObject Architecture

Started by roguan Dec 2, 2012 at 12:43 PM 3 replies 2.5k views
Original Post
roguan
roguan
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
DanDannyPantry
DanDannyPantry
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.
roguan
roguan
Fabulous! This is my current approach. It seems sustainable. Is it common?
Much appreciated.
DanDannyPantry
DanDannyPantry
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.
roguan
roguan
Hey Neglected,
Thanks for your reply, the component method seems to be working very well for me!

Good insight, mate.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.