【发布时间】:2019-09-28 23:08:46
【问题描述】:
我正在尝试创建一些基本的游戏 AI 逻辑,让一名玩家奔跑并避开另一名玩家。这很好,但是当我这样做时,我现在正在寻找防守者(以前是静态的)来追逐跑步者。我为此苦苦挣扎了很长时间,但发现 transform.up 是我一直在寻找的魔法,因为它使用玩家 Y(绿色轴)继续前进并使用旋转。
在我的 2d 平面上,跑步者跑上页面时效果很好,但我的后卫跑下来了,这就是我的问题。我预计当我在 Z 轴上将角色旋转 180 度时,transform.up 会在页面下方下降。我发现 transform.up 仍在页面上方,我我不确定我错过了什么。
为了移动玩家,我正在执行以下操作(在 Update() 内):
transform.Translate(transform.up * 15f * Time.deltaTime);
为了尝试调试问题,我在 Start() 中添加了以下内容:
// DEBUG: Show position indicators;
if (showPositionIndicators == true) {
Dictionary<string, Vector3> posIndicators = new Dictionary<string, Vector3>();
posIndicators.Add("Up", transform.up);
posIndicators.Add("Rt", transform.right);
posIndicators.Add("Dn", -transform.up);
posIndicators.Add("Lt", -transform.right);
posIndicators.Add("Fd", transform.forward);
posIndicators.Add("Bk", -transform.forward);
Vector3 scaleLocPos = new Vector3(10f, 10f, 10f);
dbgPosInd = new List<GameObject>();
foreach (KeyValuePair<string, Vector3> posIndicator in posIndicators) {
GameObject t = Instantiate(prefabPosInd, transform);
t.name = "Pos_" + posIndicator.Key;
t.transform.localPosition = Vector3.Scale(posIndicator.Value, scaleLocPos);
t.GetComponent<TextMeshProUGUI>().text = posIndicator.Key;
dbgPosInd.Add(t);
}
}
这似乎表明 transform.up 确实在“后面”并且与跑步者相同。我错过了一些简单的东西吗?这是故意的吗?我将如何让两名球员相对于他们自己的轮换前进(即都向中间跑)
[
【问题讨论】: