Commit 51715d30 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds base rotation property to rotate-to-movement constraint

parent 9fc36fe7
...@@ -17,8 +17,9 @@ double _dampenRotation(double src, double dst, double dampening) { ...@@ -17,8 +17,9 @@ double _dampenRotation(double src, double dst, double dampening) {
} }
class ConstraintRotationToMovement { class ConstraintRotationToMovement {
ConstraintRotationToMovement([this.dampening]); ConstraintRotationToMovement([this.baseRotation = 0.0, this.dampening]);
final double dampening; final double dampening;
final double baseRotation;
Point _lastPosition; Point _lastPosition;
...@@ -27,12 +28,12 @@ class ConstraintRotationToMovement { ...@@ -27,12 +28,12 @@ class ConstraintRotationToMovement {
} }
void constrain(Node node, double dt) { void constrain(Node node, double dt) {
assert(_lastPosition != null); if (_lastPosition == null) return;
if (_lastPosition == node.position) return; if (_lastPosition == node.position) return;
// Get the target angle // Get the target angle
Offset offset = node.position - _lastPosition; Offset offset = node.position - _lastPosition;
double target = degrees(GameMath.atan2(offset.dy, offset.dx)); double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation;
if (dampening == null) if (dampening == null)
node.rotation = target; node.rotation = target;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment