當前位置: 首頁>>代碼示例>>C#>>正文


C# Rigidbody2D.MoveRotation方法代碼示例

本文整理匯總了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);
        }         
    }
開發者ID:jimc1664,項目名稱:Space-Dota,代碼行數:56,代碼來源:Infantry.cs


注:本文中的UnityEngine.Rigidbody2D.MoveRotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。