From 97b64a629a95980d9a2f6c9e37b4cb44acf33a59 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 26 Oct 2020 21:33:09 +0800 Subject: =?UTF-8?q?*=E8=B7=B3=E8=B7=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Physics/PhysicsBody.cs | 42 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'Assets/Scripts/Physics/PhysicsBody.cs') diff --git a/Assets/Scripts/Physics/PhysicsBody.cs b/Assets/Scripts/Physics/PhysicsBody.cs index 8fc33fa7..b8f3b7ed 100644 --- a/Assets/Scripts/Physics/PhysicsBody.cs +++ b/Assets/Scripts/Physics/PhysicsBody.cs @@ -21,20 +21,54 @@ using UnityEngine; public sealed class PhysicsBody : MonoBehaviour { + // 是否朝向右侧(正向) + public bool IsFaceRight + { + get + { + float rotY = Quaternion.ToEulerAngles(transform.rotation).y; + rotY = Mathf.Rad2Deg * rotY; + return rotY > 0 && rotY <= 180; + } + } + + // 全局速度,以世界为参考系 [SerializeField] - private Vector3 m_Velocity; public Vector3 Velocity { get { - return m_Velocity; + Vector3 vel = m_LocalVelocity; + if (!IsFaceRight) + vel.x = -vel.x; + return vel; } - set + set { - m_Velocity = value; + if (IsFaceRight) + m_LocalVelocity = value; + else + m_LocalVelocity = new Vector3(-value.x, value.y, value.z); } } + // 以自身为参考系的速度,x>0向前,x<0向后,y>0向上,y<0向下。默认情况下以右为正方向 + // 设置速度应该以local velocity为准 + [SerializeField] + private Vector3 m_LocalVelocity; + + public Vector3 LocalVelocity + { + get + { + return m_LocalVelocity; + } + set + { + m_LocalVelocity = value; + } + } + [SerializeField] private float m_Weight; public float Weight -- cgit v1.1-26-g67d0