Skip to content

Commit c086a4f

Browse files
authored
Fix map snapping to ground. (#823)
1 parent b39ee9a commit c086a4f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

sdkproject/Assets/MapboxAR/Unity/Ar/LerpAlignmentStrategy.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ public class LerpAlignmentStrategy : AbstractAlignmentStrategy
99

1010
Vector3 _targetPosition;
1111
Quaternion _targetRotation = Quaternion.identity;
12+
bool _isAlignmentAvailable = false;
1213

1314
public override void OnAlignmentAvailable(Alignment alignment)
1415
{
1516
_targetPosition = alignment.Position;
1617
_targetRotation = Quaternion.Euler(0, alignment.Rotation, 0);
18+
_isAlignmentAvailable = true;
1719
}
1820

1921
// FIXME: this should be in a coroutine, which is activated in Align.
2022
void Update()
2123
{
22-
var t = _followFactor * Time.deltaTime;
23-
_transform.SetPositionAndRotation(
24-
Vector3.Lerp(_transform.localPosition, _targetPosition, t),
25-
Quaternion.Lerp(_transform.localRotation, _targetRotation, t));
24+
if (_isAlignmentAvailable)
25+
{
26+
var t = _followFactor * Time.deltaTime;
27+
_transform.SetPositionAndRotation(
28+
Vector3.Lerp(_transform.localPosition, _targetPosition, t),
29+
Quaternion.Lerp(_transform.localRotation, _targetRotation, t));
30+
_isAlignmentAvailable = false;
31+
}
32+
2633
}
2734
}
2835
}

sdkproject/Assets/MapboxAR/Unity/Ar/SimpleAutomaticSynchronizationContextBehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ void LocationProvider_OnLocationUpdated(Location location)
175175
, "lightblue"
176176
);
177177

178-
var position = Conversions.GeoToWorldPosition(latitudeLongitude, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz();
178+
var position = _map.GeoToWorldPosition(latitudeLongitude, false);
179+
position.y = _map.Root.position.y;
179180
_synchronizationContext.AddSynchronizationNodes(location, position, _arPositionReference.localPosition);
180181
}
181182
}

0 commit comments

Comments
 (0)