Question by
unity_mxTWsrmALoWtFQ · Apr 22 at 10:30 AM ·
gameobjects2d spritesisometricbestpracticeshowto
Proper Setup of 2d Isometric Characters (Best practice?)
First off, I'm having trouble formulating my real question here - it's more of a general "how do I approach this" kind of problem.
I've been dabbling with Unity for a while now, and while the coding parts are clear, I'm having trouble figuring out how to really do things properly when it comes to GameObject setups and such. It seems that everyone has a different approach - I'll try to illustrate my own Problems (might get a bit long-winded):
I'm trying to create a 2D isometric game with an atypical angle (it's not 45°).
The first problem I encountered here, is that the position of the GameObject is not the real position (or "center point") of the character on an isometric plane. I need this "center point", for collisions, path finding, etc. The only solution I found here, was to add a child object that is just a point.
So, my structure now would look like this:
Character A - Character A Center
To find the center point, I use it as a parameter "center" on the parent object "Character A".
Already, I have to ask myself if this is a bad approach, but let's continue:
Next, I soon realized that dealing with Animations had their own problems: Certain animations have different offsets. They aren't all perfectly aligned (for example, a sprite sheet for someone standing is less wide than someone kicking). In addition, the center point of the character isn't necessarily the center point of the animation (again, kicking out makes the sprite wider, but the actual center of the character would be where the standing leg is).
Ultimately, I saw myself forced, to create another child object: the "body". So now my Structure is:
Character A - Character A Body - Character A Center
And again, the "body" becomes a parameter for "Character A".
"Character A" contains all the scripts, like path finding, Seeker, etc.
"Character A Body" contains the Sprite Renderer, Animator, Rigidbody 2D and Collider 2D.
"Character A Center" is just a transform.
So far so good, this seems to work fine, my NPC enemies can walk around, animations are aligned properly, their "center of mass" is properly offset.
But then I realize: I cannot apply this methodology to my Player character.
The key difference here is: My NPC's are being moved by A* pathfinding. This directly moves them, and the path finding script is on "Character A" (the parent GameObject). In other words: the pathfinding moves the parent object (and all children) directly.
My playable character is being moved by RigidBody.velocity; but the RigidBody (the "body") is a child of the parent, which holds the controller. So now, the child is being moved around, while the parent doesn't get moved.
Of course, I could start trying to fix this by just applying the child position to the parent position, but I would expect to find a solution that works equally for all characters on screen without any exceptions for the player character (what if I could suddenly mind-control another NPC in-game? Player controls should be independent of the GameObject structure, right?). Even then, adjusting the parent position to follow the child seems like a very bad solution.
But this brings me to a conclusion I've had long before: I have no clue how things are actually put together in a 2D game like this. I can find tutorials for little parts (how to do pathfinding, how to do dialogue, how to interact with other game objects, collisions, etc) - but my question is, how is all of this actually properly put together? What's a good structure to avoid the issues I've been having? Do "real" games rely on character game objects with dozens of children or just somehow cram everything into one massive game object?
And how do you guys deal with Animator offsets? I've not found any way to offset an animation by x,y without having it inside it's own child - this seems off.
Comment