void FixedUpdate() { // if fixed, then avoid any update & mark as unsaturated if (!this.m_bIsMoving) { this.m_bIsSaturated = false; this.m_bIsAccelerating = false; return; } // check if(!this.m_bIsSaturated && this.m_bIsAccelerating) { // saturate velocity when max speed is reached if (this.gameObject.GetComponent<UnityEngine.Rigidbody>().velocity.magnitude > this.m_targetVelocity.magnitude) { // log UnityEngine.Debug.Log( "<color=Blue>Info: </color> ApollonSimulatedRobosoftEntityBehaviour.FixedUpdate() : saturation event ! [ actual:" + this.gameObject.GetComponent<UnityEngine.Rigidbody>().velocity + "{mag:" + this.gameObject.GetComponent<UnityEngine.Rigidbody>().velocity.magnitude + "}" + " > target:" + this.m_targetVelocity + "{mag:" + this.m_targetVelocity.magnitude + "}" + " ]" ); // saturate this.gameObject.GetComponent<UnityEngine.Rigidbody>().AddForce(this.m_targetVelocity, UnityEngine.ForceMode.VelocityChange); // mark as saturated this.m_bIsSaturated = true; } /* if() */ } /* if() */ // so now apply acceleration depending on current saturation if (!this.m_bIsSaturated && this.m_bIsAccelerating) { // continuous accel this.gameObject.GetComponent<UnityEngine.Rigidbody>().AddForce(this.m_continuousAcceleration, UnityEngine.ForceMode.Acceleration); } /* if() */ // update linked game object transform first from current behaviour transform UnityEngine.Vector3 position = UnityEngine.Vector3.zero; UnityEngine.Quaternion rotation = UnityEngine.Quaternion.identity; position.Set( this.gameObject.transform.position.x, this.gameObject.transform.position.y, this.gameObject.transform.position.z ); rotation.Set( this.gameObject.transform.rotation.x, this.gameObject.transform.rotation.y, this.gameObject.transform.rotation.z, this.gameObject.transform.rotation.w ); this.skeletonRoot.transform.SetPositionAndRotation(position, rotation); } /* FixedUpdate */
internal static void Interpolate(JToken a, JToken b, float linearT, ref JToken mix, CubicBezier easing) { var easedT = easing.Sample(linearT); // compound types if (a.Type == JTokenType.Object) { JObject A = (JObject)a; JObject B = (JObject)b; JObject Mix = (JObject)mix; if (A.ContainsKey("x") && A.ContainsKey("y")) { if (A.ContainsKey("z")) { // quaternion if (A.ContainsKey("w")) { tempA.Set(A.ForceFloat("x"), A.ForceFloat("y"), A.ForceFloat("z"), A.ForceFloat("w")); tempB.Set(B.ForceFloat("x"), B.ForceFloat("y"), B.ForceFloat("z"), B.ForceFloat("w")); tempMix = Quaternion.Slerp(tempA, tempB, easedT); Mix.SetOrAdd("x", tempMix.x); Mix.SetOrAdd("y", tempMix.y); Mix.SetOrAdd("z", tempMix.z); Mix.SetOrAdd("w", tempMix.w); } // Vector3 else { Mix.SetOrAdd("x", UnityMath.Lerp(A.ForceFloat("x"), B.ForceFloat("x"), easedT)); Mix.SetOrAdd("y", UnityMath.Lerp(A.ForceFloat("y"), B.ForceFloat("y"), easedT)); Mix.SetOrAdd("z", UnityMath.Lerp(A.ForceFloat("z"), B.ForceFloat("z"), easedT)); } } // Vector2 else { Mix.SetOrAdd("x", UnityMath.Lerp(A.ForceFloat("x"), B.ForceFloat("x"), easedT)); Mix.SetOrAdd("y", UnityMath.Lerp(A.ForceFloat("y"), B.ForceFloat("y"), easedT)); } } // TODO: other compound types (color3, color4) } // simple types else { JValue A = (JValue)a; JValue B = (JValue)b; JValue Mix = (JValue)mix; // numeric types if (a.Type == JTokenType.Float || a.Type == JTokenType.Integer) { Mix.Value = UnityMath.Lerp(A.ForceFloat(), B.ForceFloat(), easedT); } // no interpolation available, just use A else { Mix.Value = A.Value; } } }