Пример #1
0
 /// <summary>
 /// clears all internal forces for the spring
 /// </summary>
 public static void ClearForces(ref Spring spring)
 {
     spring.m_InternalFrames    = 0;
     spring.m_InternalSoftForce = float3.zero;
     spring.m_InternalForce     = float3.zero;
 }
Пример #2
0
        /// <summary>
        /// adds a force distributed over up to 120 fixed frames
        /// </summary>
        public static void AddSoftForce(ref DynamicBuffer <SoftForceElement> softForce, ref Spring spring, float3 force,
                                        float frames, float timeScale)
        {
            force /= timeScale;

            frames = Mathf.Clamp(frames, 1, 120);

            AddForceInternal(ref spring, force / frames, timeScale);

            for (int v = 0; v < (Mathf.RoundToInt(frames) - 1); v++)
            {
                softForce[v] += (force / frames);
            }
        }
Пример #3
0
 /// <summary>
 /// instantly kills any forces added to the spring, gradually
 /// easing them back in over 'seconds'.
 /// this is useful when you need a spring to freeze up for a
 /// brief amount of time, then slowly relaxing back to normal.
 /// </summary>
 public static void ForceVelocityFadeIn(ref Spring spring, float seconds)
 {
     spring.VelocityFadeInLength  = seconds;
     spring.VelocityFadeInEndTime = Time.time + seconds;
     spring.VelocityFadeInCap     = 0.0f;
 }
Пример #4
0
 /// <summary>
 /// stops spring velocity and resets state to the static
 /// equilibrium
 /// </summary>
 private static void Reset(ref Spring spring)
 {
     spring.Velocity = float3.zero;
     spring.State    = spring.RestState;
 }