当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.RotateBy方法代码示例

本文整理汇总了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);
		}
开发者ID:mswf,项目名称:game-a-week,代码行数:29,代码来源:PlayerController.cs

示例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;
		}
开发者ID:mswf,项目名称:game-a-week,代码行数:71,代码来源:PlayerController.cs


注:本文中的UnityEngine.Vector3.RotateBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。