本文整理汇总了C#中UnityEngine.Vector3.RotateBy方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.RotateBy方法的具体用法?C# Vector3.RotateBy怎么用?C# Vector3.RotateBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Vector3
的用法示例。
在下文中一共展示了Vector3.RotateBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestProng
protected void TestProng(Vector3 direction, out float middleSpace, out float leftSpace, out float rightSpace)
{
var cap = _characterCapsuleCollider;
var center = cap.center;
var sideWaysDirection = direction.RotateBy(90f * Mathf.Deg2Rad);
var middleRay = new Ray(_transform.position + center, direction);
var leftRay = new Ray(_transform.position + center + sideWaysDirection*cap.radius, direction);
var rightRay = new Ray(_transform.position + center - sideWaysDirection * cap.radius, direction);
middleSpace = GetSpaceAhead(middleRay);
leftSpace = GetSpaceAhead(leftRay);
rightSpace = GetSpaceAhead(rightRay);
var dt = Time.fixedDeltaTime;
DebugExtension.DebugPoint(_transform.position + center, Color.yellow, 1f, dt, false);
DebugExtension.DebugRay(_transform.position + center, direction * middleSpace, Color.blue, dt, false);
DebugExtension.DebugPoint(_transform.position + center + sideWaysDirection * cap.radius, new Color(1, 0, 0, 0.5f), 1f, dt);
DebugExtension.DebugRay(_transform.position + center + sideWaysDirection * cap.radius, direction * leftSpace, Color.blue, dt, false);
DebugExtension.DebugPoint(_transform.position + center - sideWaysDirection * cap.radius, new Color(1, 0, 0, 0.5f), 1f, dt);
DebugExtension.DebugRay(_transform.position + center - sideWaysDirection * cap.radius, direction * rightSpace, Color.blue, dt, false);
}
示例2: AdjustDirectionForObstacles
protected Vector3 AdjustDirectionForObstacles(Vector3 initialDirection, float maxRotation = 65f)
{
const float rotationSteps = 5f;
float rotationAmount = 0f;
Vector3 adjustedDirection = new Vector3(initialDirection.x, initialDirection.y, initialDirection.z);
int numberOfLoops = 0;
while (Mathf.Abs(rotationAmount) <= maxRotation && numberOfLoops < 100)
{
numberOfLoops++;
float middleSpace, leftSpace, rightSpace;
TestProng(adjustedDirection.normalized, out middleSpace, out leftSpace, out rightSpace);
const float margin = 0.1f;
// rotate left
if (Mathf.Approximately(leftSpace, rightSpace))
{
return adjustedDirection;
}
else if (leftSpace > rightSpace)
{
// try steer right
if (middleSpace < leftSpace - margin || rightSpace < middleSpace - margin)
{
adjustedDirection = adjustedDirection.RotateBy(rotationSteps*Mathf.Deg2Rad);
rotationAmount += rotationSteps;
}
// try steer left
else if (middleSpace < rightSpace - margin || leftSpace < middleSpace - margin)
{
adjustedDirection = adjustedDirection.RotateBy(-rotationSteps*Mathf.Deg2Rad);
rotationAmount -= rotationSteps;
}
else
{
return adjustedDirection;
}
}
else
{
// try steer left
if (middleSpace < rightSpace - margin || leftSpace < middleSpace - margin)
{
adjustedDirection = adjustedDirection.RotateBy(-rotationSteps * Mathf.Deg2Rad);
rotationAmount -= rotationSteps;
}
// try steer right
else if (middleSpace < leftSpace - margin || rightSpace < middleSpace - margin)
{
adjustedDirection = adjustedDirection.RotateBy(rotationSteps * Mathf.Deg2Rad);
rotationAmount += rotationSteps;
}
else
{
return adjustedDirection;
}
}
}
//if (numberOfLoops > 80)
//Debug.Log(numberOfLoops);
return adjustedDirection;
}