<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9BR09KVFQ5LnBuZz8xIn0=” alt =“替代文字”>
在上图中
在下面的代码中,orientation
是代表地形法线的向量,因此蜘蛛与之对齐:
Vector3 orientation = GetTerrainNormal();
Quaternion rotationNeeded = Quaternion.FromToRotation(Vector3.up, orientation);
transform.rotation = Quaternion.RotateTowards(
transform.rotation,
rotationNeeded,
RotationSpeed * Time.deltaTime
);
我的问题是,我无法设法使蜘蛛面向目标。当我添加任何使蜘蛛朝其旋转的代码时,它不再与地形的法线对齐,而是直说...
因此,基本上,如何使蜘蛛绕Y世界轴旋转(我认为),然后仍然旋转以匹配斜率?
尝试一下
Vector3 directionToTarget = target.transform.position - transform.position;
Quaternion rotationNeeded = Quaternion.LookRotation(directionToTarget, orientation);