本文整理匯總了C#中UnityEngine.Rigidbody2D.MoveRotation方法的典型用法代碼示例。如果您正苦於以下問題:C# Rigidbody2D.MoveRotation方法的具體用法?C# Rigidbody2D.MoveRotation怎麽用?C# Rigidbody2D.MoveRotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UnityEngine.Rigidbody2D
的用法示例。
在下文中一共展示了Rigidbody2D.MoveRotation方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: update
static void update(Transform Trnsfrm, Rigidbody2D Body, Infantry U, ref int SPi, ref bool PathActive) {
Vector2 Pos = Body.position, Vel = Body.velocity;
float Ang = Body.rotation;
float AngVel = Body.angularVelocity;
Vector2 Fwd = new Vector2(-Mathf.Sin(Ang * Mathf.Deg2Rad), Mathf.Cos(Ang * Mathf.Deg2Rad));
Vector2 Vec = U.SmoothPath[SPi] - Pos;
float Mag = Vec.magnitude;
if(PathActive) {
for(; ; ) {
if(SPi < U.SmoothPath.Count - 1) {
var v2 = U.SmoothPath[SPi + 1] - Pos;
if(Vector2.Dot(Vec, v2) < -0.1f) {
SPi++;
Vec = v2;
} else {
Mag = Vec.magnitude;
break;
}
} else {
Mag = Vec.magnitude;
if(Mag < U.RoughRadius *0.75 )
PathActive = false;
break;
}
}
Mag *= 2; Vec *= 2;
for(; ; ) {
if(Mag > U.MaxSpeed) {
Vec = Vec * U.MaxSpeed / Mag;
break;
}
if(SPi >= U.SmoothPath.Count - 1) break;
var v2 = U.SmoothPath[SPi + 1] - U.SmoothPath[SPi];
var vn = Vec / Mag;
float dt2 = Vector2.Dot(v2, vn);
if(dt2 > 0) {
Mag += dt2;
Vec = vn * Mag;
} else break;
}
Body.velocity = Vector2.Lerp(Body.velocity, Vec, U.Acceleration * Time.deltaTime);
var dy = Mathf.Rad2Deg * Mathf.Atan2(-Vec.x, Vec.y);
Body.MoveRotation(Mathf.LerpAngle(Ang, Mathf.MoveTowardsAngle(Ang, dy, 1080 * Time.deltaTime), U.MaxTurnSpeed * Time.deltaTime));
} else {
if(U.FireTarget != null) {
Body.MoveRotation(Mathf.LerpAngle(Ang, Mathf.MoveTowardsAngle(Ang, U.TargetAng, 1080 * Time.deltaTime), U.MaxTurnSpeed * Time.deltaTime));
}
Body.velocity = Vector2.Lerp(Body.velocity, Vector2.zero, 1.5f *U.Acceleration * Time.deltaTime);
}
}