c# - 玩家不再向左移动
问题描述
想要翻转火点,现在玩家不再向左移动。
void Update()
{
float h = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * h * movSpeed * Time.deltaTime);
if (h > 0 && !facingRight)
{
Flip();
}
else if (h < 0 && facingRight)
{
Flip();
}
}
private void Flip()
{
facingRight = !facingRight;
transform.Rotate(0f, 180f, 0f);
}
解决方案
Transform.Translate
如果不使用第二个参数,则在相对于对象的坐标空间中移动。因为你在翻转它,所以你总是朝着同一个方向移动。链接的文档指出:
If
relativeTo
被忽略或设置为Space.Self
相对于变换的局部轴应用移动。
您想Space.World
用作第二个参数(默认为Space.Self
):
transform.Translate(Vector3.right * h * movSpeed * Time.deltaTime, Space.World);
推荐阅读
- java - 有没有办法在服务器上一次将所有 jsp 文件转换为静态页面?
- html - 尝试在标题中显示徽标
- css - 水平表单行内的 Bootstrap 4 垂直居中文本
- php - 如何在laravel中搜索给定距离和给定纬度和经度的所有位置
- php - 根目录下 index.php 中的 Laravel 5.2 恶意代码
- r - is.finite(x) 中的 ggplot 错误并且不知道如何选择比例
- c# - C# 如何在大约 500-700 毫秒内找到较大图像中的图像?
- java - 如何附加到文件中每一行的末尾,而不合并或替换文件中的下一行?
- r - 从 R 中的数据框列表中寻找列中的任何真值
- python - 需要帮助来理解 SimpleImputer 类中详细的目的