Skip to content

Commit a0b0b45

Browse files
committed
added flag to flip gravity.
1 parent 3715e7c commit a0b0b45

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Runtime/Scripts/Sensors/IMU/ZOIMU.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ namespace ZO.Sensors {
1616
public class ZOIMU : ZOGameObjectBase, ZOSerializationInterface {
1717

1818
[Header("IMU Parameters")]
19-
public String _imuId = "none";
19+
public bool _flipGravity = false;
20+
21+
/// <summary>
22+
/// Flips gravity vectory.
23+
/// Why would you: the accelerometer is an intertial sensor and it measures inertial force.
24+
/// The accelerometer doesn’t measure G-force, but rather the force that resists to G.
25+
/// The resisting force aims up to the ceiling.
26+
/// </summary>
27+
/// <value></value>
28+
public bool FlipGravity {
29+
get {return _flipGravity;}
30+
set {_flipGravity = value;}
31+
}
2032

2133

2234
[Header("Noise Models")]
@@ -102,7 +114,14 @@ protected override async void ZOFixedUpdate() {
102114
Vector3 prevAcceleration = _acceleration;
103115
_acceleration = (velocity - _lastVelocity) / Time.fixedDeltaTime;
104116
_lastVelocity = velocity;
105-
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity);
117+
118+
// apply gravity
119+
if (FlipGravity == true) {
120+
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity * -1);
121+
} else {
122+
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity);
123+
}
124+
106125
_acceleration = _linearNoise.Apply(_acceleration);
107126
_acceleration = ZO.Math.ZOMathUtil.lowPassFilter(_acceleration, prevAcceleration, _preFilterAccelerationAlpha);
108127

@@ -117,7 +136,7 @@ protected override async void ZOFixedUpdate() {
117136

118137

119138
if (OnPublishDelegate != null) {
120-
await OnPublishDelegate(this, _imuId, publishedAcceleration, publishedAngularVelocity, publishedOrientation);
139+
await OnPublishDelegate(this, Name, publishedAcceleration, publishedAngularVelocity, publishedOrientation);
121140
}
122141

123142
}

0 commit comments

Comments
 (0)