Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Pan_Migo · Jul 24, 2018 at 10:04 AM · programmingoop

OOP architexture analysis

Hello Unity friends ,

I have finished creating a camera that is implemented using a rigid Body rather than a character controller. Because I am about to release the source code on GitHub I will need some suggestions in terms of general OOP architexture of the camera.

More specifically there are three classes :

  • FPMovementController (that handles all the player moves)

  • Camera controller (that handles camera rotation and general camera actions)

  • CameraHeadBob (handles the camera headbob action).

1) FPMovementController is assigned to the parent gameobject and has a simple dependency with the CameraHeadBob class

2) CameraController is assigned to the child of the parent object and is not dependant from the other scripts

3) CameraHeadBod is assigned to the child and has a dependency with the FPMovementController.

What I would like to ask is weather this software architecture is good enough or can be further updated to match the norms of OPP programming. Also is it better to break the movements of the player to different classes (Jumping , running , etc ) even if more classes and dependencies, associations will arise ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Jul 24, 2018 at 11:48 AM

What is a bit strange is that you seem to have a two way dependency between FPMovementController and your CameraHeadBob class. But, why? Shouldn't the head bob just be driven by the FPMovementController? When you have a strongly typed two way relation ship between two classes they both can only come in pairs as each requires the other one.


So are you sure you need this two way coupling between your classes?. Also what exactly is that coupling used for? You may replace the strong coupling with a loose one by using an interface to communicate. Also keep in mind components are modules. It's highly adviced that each module works on it's own. Dependencies are fine but if they should provide a general solution you should make it possible to either remove some of the dependencies if they aren't needed or allow the user to replace it with a different implementation.


If the classes are meant to maybe serve as baseclass for the user so he can extend the functionality of it. Make sure you made the right things virtual / protected / private. As we don't have the slightest clue about how your code looks like this is all we can suggest by poking around in the dark.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pan_Migo · Jul 24, 2018 at 01:56 PM 0
Share

Well the coupling is somewhat needed for the specific design. The specific coupling between the classes was made cause both of them wanting to address fields from each class so a specific behaviour can be accomplished.

However I would be really interesting hearing more about the interface you suggest to serve as a bridge between the two classes, maybe an general example would fit , cause I can really find a positive result from following this pattern.



You can also check the code here is this repo (under construction). https://github.com/Pan$$anonymous$$ig/First-Person-Unity-Camera

Thank you in advance for your time.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Is there a way to create new GameObjects in your scene from constructors? 3 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer

Organizing Enemy Movement Types 0 Answers

Best way to maintain a list of selected objects? (Static Classes?) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges