简体   繁体   English

Unity 中损坏的 2D 平台游戏翻转

[英]Broken 2D Platformer Flip In Unity

I am creating a platformer game in Unity.我正在 Unity 中创建一个平台游戏。 The character I am using for the player has a very disproportionate and long body, and the player movement script I have implemented doesn't understand where the base of the body is supposed to be(?) Because of this, when the character flips to go in a different direction it seems as if the player is teleporting, even though they are not.我为玩家使用的角色有一个非常不成比例的长身体,我实现的玩家移动脚本不明白身体的底部应该在哪里(?)因此,当角色翻转到朝着不同的方向前进,似乎玩家正在传送,即使他们不是。 I assume that the only way to fix this is to change the position of the player directly after they flip, but either way I don't know how to do that.我认为解决这个问题的唯一方法是在玩家翻转后直接改变玩家的位置,但无论哪种方式我都不知道该怎么做。

private void Flip()
{
    // Switch the way the player is labelled as facing.
    m_FacingRight = !m_FacingRight;

    // Multiply the player's x local scale by -1.
    Vector3 theScale = transform.localScale;
    theScale.x *= -1f;
    transform.localScale = theScale;
}

I would not recommend manually repositioning the sprite in code.我不建议在代码中手动重新定位精灵。 I think changing the sprite's pivot point in the sprite editor should fix your problem.我认为在精灵编辑器中更改精灵的枢轴点应该可以解决您的问题。
See:看:
https://forum.unity.com/threads/sprite-is-not-aligned-at-center.493552/ https://forum.unity.com/threads/sprite-is-not-aligned-at-center.493552/

https://docs.unity3d.com/Manual/SpriteEditor.html https://docs.unity3d.com/Manual/SpriteEditor.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM