适当的游戏对象结构以及如何移动父对象,当孩子移动 /包含刚体
我对这个主题有几个问题,但是由于某些原因,我最终不得不将玩家角色分为父对象和几个子对象。我现在会尝试关注这个问题。
首先,这与2D等距游戏中的字符有关。
这导致了拥有所有脚本的父对象,而实际的主体(Ridigbody 2D,动画师,Sprite Renderer,Collider)在一个单独的子对象中。
我通过更改“玩家身体”刚体速度来控制播放器,就像我在大量教程中看到的那样 - 这很好:
this.rigidBody.velocity = velocity;
由于刚性机体是子对象,所以父母没有移动与它。
问题是,我需要能够抵消不同的动画,而除了将spritererer和Animator与父对象分开,我没有其他方法可以做到这一点。因此,现在,我可以选择能够抵消动画或正确移动父对象。
显然,我正在以错误的方式处理此问题 - 但是我找不到有关2D等轴测空间中字符的适当游戏对象结构的看法。我对角色的“中心点”也有同样的问题,这不是游戏对象的左上角。
我的问题是:
我应该如何最好地构建角色游戏对象,以避免这种问题,同时保留抵消动画的能力?一切都塞在一个巨大的游戏对象中,还是将事物拆分为正确的方法?
我应该只保留结构并与孩子一起移动父母吗?这似乎更像是一个黑客,而不是解决方案。
我只是在找出有关如何做这些事情的适当设置以及专业游戏如何接近此事的适当设置,因为我能找到的任何教程总是专注于单个方面,而不是如何将它们整合在一起。
I have several questions around this topic, but for certain reasons I ended up having to split the Player character into a parent object and several child objects. I'll try to focus on this question for now.
First of all, this relates to characters in a 2D Isometric game.
This lead to the parent object holding all the scripts, while the actual body (Ridigbody 2D, Animator, Sprite Renderer, Collider) are in a separate child object.
I control the player by altering the "Player Body" rigidbody velocity, as I've seen in plenty of tutorials - this works perfectly fine:
this.rigidBody.velocity = velocity;
Since the rigidbody is a child object, the parent is not moved with it.
The thing is, I need to be able to offset different animations and I found no other way to do so, than to separate SpriteRenderer and Animator from the parent object. So now, I have the choice between being able to offset animations, or move the parent object properly.
Clearly, I'm approaching this in a wrong way - but I can't find resources on how a proper GameObject structure for characters in a 2d isometric space should look. I've had the same issue with the "center point" of the character, which isn't the top-left corner of the game object.
My question is:
How should I best structure my character GameObjects to avoid this kind of issue, while retaining the ability to offset animations? Is everything stuffed in one massive game object, or is splitting things up the right approach?
Should I just keep the structure and move the parent with the child? This seems more like a hack than a solution.
I'm just having trouble figuring out the proper setup on how to do these things, and how professional games might approach this, since any tutorials I can find are always focused on single aspects and not on how to put them all together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将刚性体放在根部,以便每当移动其他一切时都会移动。然后,您可以将子对象上的其他组件分开。
编辑1:忘记说明主要对撞机应在具有刚体的同一游戏对象上(在这种情况下为根)。
Put the rigidbody in the root so that whenever it moves everything else will move along. Then you may separate the other components on the child objects.
Edit 1: Forgot to state that the main collider should be on the same gameobject that has the rigidbody (in this case, the root).