Jump to content
  • Advertisement
Sign in to follow this  
roguan

Camera, Player, and GameObject Architecture

This topic is 2203 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.

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

Share this post


Link to post
Share on other sites
Advertisement
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
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
Sign in to follow this  

  • 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!