Search Unity

unity best practice for ground check and other basic physics

Discussion in 'Scripting' started by prototyped, Aug 6, 2020.

  1. prototyped

    prototyped

    Joined:
    May 31, 2013
    Posts:
    18
    Good after mornevening lol so question i made a ground check class that has different classes in it that will check for a game object being grounded as well as handle any animations that are needed for the ground check, like isGrounded triggers, So i thought i should make a singleton of this then i thought that i don't need to. Is my only option is just to attach that component to every single game object that checks for the gound or is there another way so that the game object isn't just one long script component mess?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    This is kind of the point of Unity's Object-Component model. When an object needs a behavior, you attach a component that provides that behavior.

    What benefit would that provide? Isn't the is grounded check object-specific?

    What do you mean by "script component mess"?
     
  3. prototyped

    prototyped

    Joined:
    May 31, 2013
    Posts:
    18
    1. yes but if its boilerplate id rather it be something that you can refer to than just constant drag and drop.
    2. that's why I threw the idea away
    3. I have a fear of making monolithic code as well as bearing down a whole bunch of components on one object
    there's nothing special really about the ground check class, as stated its pretty boilerplate, all the unique stuff can be handled in other classes so im thinking there has to be a smarter way to implement this.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    How much drag and drop are you imagining? How many different types of objects need a ground check? (I Know nothing about your game). You are using prefabs in your workflow right?

    You're afraid of two dimetric opposites!
    Transforms and colliders and Audio sources and Renderers are boilerplate too, and they're all components in Unity. That's the beauty of components. You can easily reuse the boilerplate stuff by attaching them to GameObjects.
     
  5. prototyped

    prototyped

    Joined:
    May 31, 2013
    Posts:
    18
    I am and every enemy and every player the game has a character action feel so theres a lot of ground checking

    [QUOTE="PraetorBlue, post: 6174196, member: 166058]You're afraid of two dimetric opposites![/QUOTE]

    No more like those are my two options either you make a large class or smaller classes but a lot of components

    [QUOTE="PraetorBlue, post: 6174196, member: 166058]Transforms and colliders and Audio sources and Renderers are boilerplate too, and they're all components in Unity. That's the beauty of components. You can easily reuse the boilerplate stuff by attaching them to GameObjects.[/QUOTE]
     
  6. prototyped

    prototyped

    Joined:
    May 31, 2013
    Posts:
    18
    Oof that ain't work