@@ -77,14 +77,13 @@ public enum RayRefinementStep
7777 /// </summary>
7878 public class RayRefinement : RefinementController , IInputClickHandler
7979 {
80- private Vector3 keepLocation ; // HACK:
81-
8280 #region Constants
8381 private const float DEF_SCALE = 0.05f ;
8482 #endregion // Constants
8583
8684 #region Member Variables
8785 private RayRefinementStep currentStep ; // What step we're on in the refinement
86+ private Vector3 lastTargetPosition ; // The last position where a target was placed
8887 private GameObject modelDirection ; // GameObject instance representing the models direction
8988 private LineRenderer modelLine ; // Used to render a line pointing from the model origin in the model direction
9089 private GameObject modelOrigin ; // GameObject instance representing the models origin
@@ -182,6 +181,10 @@ private void CreateTarget(GameObject prefab, ref GameObject target, string name)
182181 // Create prefab
183182 target = GameObject . Instantiate ( prefab ) ;
184183
184+ // Start this target at the same location as the last target
185+ // or near the user if there is no last target position
186+ target . transform . position = ( lastTargetPosition != Vector3 . zero ? lastTargetPosition : CameraCache . Main . transform . position ) ;
187+
185188 // Make sure it's active (in case inactive due to auto generation)
186189 target . SetActive ( true ) ;
187190
@@ -299,8 +302,6 @@ private void NextStep()
299302 // Update parent rotation, but around placement origin
300303 gameObject . transform . RotateAround ( placementOriginWorld , Vector3 . up , rotation ) ;
301304
302- // HACK: keepLocation = placementOriginWorld;
303-
304305 // Finish refinement
305306 FinishRefinement ( ) ;
306307
@@ -327,10 +328,11 @@ private void StopAndCleanup()
327328 // Cleanup resources
328329 Cleanup ( ref modelOrigin ) ;
329330 Cleanup ( ref modelDirection ) ;
330- // HACK:
331- //Cleanup(ref placementOrigin);
332- //Cleanup(ref placementDirection);
331+ Cleanup ( ref placementOrigin ) ;
332+ Cleanup ( ref placementDirection ) ;
333333
334+ // Reset placeholders
335+ lastTargetPosition = Vector3 . zero ;
334336 modelLine = null ;
335337 placementLine = null ;
336338 targetInterpolator = null ;
@@ -439,12 +441,6 @@ protected override void Update()
439441 // Pass to base first
440442 base . Update ( ) ;
441443
442- // HACK:
443- if ( keepLocation != Vector3 . zero )
444- {
445- gameObject . transform . RotateAround ( keepLocation , Vector3 . up , Time . deltaTime * 20 ) ;
446- }
447-
448444 // If not moving targets, nothing to do
449445 if ( currentStep == RayRefinementStep . None || currentStep == RayRefinementStep . Refinement ) { return ; }
450446
@@ -464,8 +460,11 @@ protected override void Update()
464460 RaycastHit hitInfo ;
465461 if ( Physics . Raycast ( cameraTransform . position , cameraTransform . forward , out hitInfo , maxDistance , layers ) )
466462 {
463+ // Store new position as last
464+ lastTargetPosition = hitInfo . point ;
465+
467466 // Tell the target to move to the new position
468- targetInterpolator . SetTargetPosition ( hitInfo . point ) ;
467+ targetInterpolator . SetTargetPosition ( lastTargetPosition ) ;
469468
470469 // Target has been placed
471470 targetPlaced = true ;
0 commit comments