void FixedUpdate() { if (!XMath.FloatEqual(this.mMomentum, Vector3.zero)) { Vector3 velocity = GetComponent <Rigidbody>().velocity; Vector3 velocityChange = this.mMomentum - velocity; velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange); velocityChange.y = 0; velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange); GetComponent <Rigidbody>().AddForce(velocityChange, ForceMode.VelocityChange); } // We apply gravity manually for more tuning control GetComponent <Rigidbody>().AddForce(new Vector3(0, -gravity * GetComponent <Rigidbody>().mass, 0)); mGrounded = false; }
public static bool FloatEqual(Vector3 a, Vector3 b) { return(XMath.FloatEqual(a.x, b.x) && XMath.FloatEqual(a.y, b.y) && XMath.FloatEqual(a.z, b.z)); }
public static bool FloatEqual(Vector2 a, Vector2 b) { return(XMath.FloatEqual(a.x, b.x) && XMath.FloatEqual(a.y, b.y)); }
bool Approximately(Vector3 a, Vector3 b) { return(XMath.FloatEqual(a.x, b.x) && XMath.FloatEqual(a.y, b.y) && XMath.FloatEqual(a.z, b.z)); }