Add Spring Animation Support
Hi! Bro! Also remember issues188๏ผ I now finally have enough time and motivation to finish it!
This PR introduces physics-based spring animations to LitMotion, bringing natural and responsive motion that simulates real-world spring physics.
๐ฏ What are Spring Animations?
Spring animations are physics-based animations that simulate the behavior of real-world springs. Unlike traditional linear or easing-based animations, spring animations create motion that starts with high velocity and gradually settles into the target position, mimicking natural physical laws. This creates a more organic and intuitive user experience that feels connected to the real world.
As demonstrated in Apple's Spring Animation Design Principles, spring animations are fundamental to creating fluid, responsive interfaces that users find natural and engaging.
๐ Why Spring Animations are Superior to Traditional Tweens
1. Natural Physics Simulation
- Tween: Linear or curved interpolation between start and end values
- Spring: Realistic physics with acceleration, deceleration, and natural settling
2. Velocity Preservation
- Tween: Abrupt stops when interrupted, losing all momentum
- Spring: Smooth transitions that preserve velocity when changing targets
3. Dynamic Response
- Tween: Fixed duration and easing curve regardless of distance
- Spring: Adaptive motion that responds to target distance and current velocity
4. Continuous Tracking
- Tween: Requires manual recreation for target changes
- Spring: Can continuously track moving targets with natural physics
๐ Usage Examples
// Basic spring animation - much more natural than linear tweens
var motion = LMotion.Spring.Create(0f, 100f, SpringOptions.Critical)
.Bind(value => transform.position.x = value);
// Continuous tracking - impossible with traditional tweens
var followMotion = LMotion.Spring.Create(currentPos, mousePos, SpringOptions.Overdamped)
.WithLoops(-1, LoopType.Incremental)
.Bind(value => transform.position = value);
// Custom physics parameters for fine-tuned control
var options = new SpringOptions(stiffness: 15f, dampingRatio: 0.8f);
var motion = LMotion.Spring.Create(Vector3.zero, targetPosition, options)
.Bind(value => transform.position = value);
๐ง Implementation Details
- Backward Compatible: Existing LitMotion code continues to work unchanged
- Zero GC Design: Uses structs and value types for memory efficiency
- Burst Optimized: Leverages Unity's Burst compiler for maximum performance
- SIMD Accelerated: Utilizes float4 operations for vectorized calculations
๐งช Testing
Comprehensive test cases and examples are available in Assets\LitMotion\samples\LitMotion.Spring, including:
- Visual demonstration comparing spring vs traditional tween animations
- Performance benchmarks showing spring superiority
- Interactive parameter adjustment tools
- Multi-language support (English, Chinese, Japanese)
Test results show that the Spring implementation maintains LitMotion's high performance goal. 1,000,000 Spring animations even consume less energy than Tween!
๐ Documentation
I've uploaded three documents: the description, API documentation, and feature documentation. When you merge them, you can update them into the original documents!