繁体   English   中英

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

[英]Broken 2D Platformer Flip In Unity

我正在 Unity 中创建一个平台游戏。 我为玩家使用的角色有一个非常不成比例的长身体,我实现的玩家移动脚本不明白身体的底部应该在哪里(?)因此,当角色翻转到朝着不同的方向前进,似乎玩家正在传送,即使他们不是。 我认为解决这个问题的唯一方法是在玩家翻转后直接改变玩家的位置,但无论哪种方式我都不知道该怎么做。

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;
}

我不建议在代码中手动重新定位精灵。 我认为在精灵编辑器中更改精灵的枢轴点应该可以解决您的问题。
看:
https://forum.unity.com/threads/sprite-is-not-aligned-at-center.493552/

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

暂无
暂无

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

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