diff --git a/js/balloons-and-static-electricity/model/BalloonModel.js b/js/balloons-and-static-electricity/model/BalloonModel.js index 9c6e42b5..ac5dec74 100644 --- a/js/balloons-and-static-electricity/model/BalloonModel.js +++ b/js/balloons-and-static-electricity/model/BalloonModel.js @@ -143,7 +143,7 @@ class BalloonModel { phetioReadOnly: true } ); - // @public {Vector2} + // @public {Vector2} - The velocity of the balloon when moving freely, i.e. NOT when it is being dragged. // use new Vector2( 0, 0 ) instead of Vector2.ZERO so equality check won't be thwarted by ImmutableVector2 this.velocityProperty = new Vector2Property( new Vector2( 0, 0 ), { tandem: tandem.createTandem( 'velocityProperty' ), @@ -282,8 +282,8 @@ class BalloonModel { this.positionProperty.get().y + this.height ); - // when position changes, update bounds of balloon in play area, direction of movement, and whether or not the - // the balloon is touching an object - no need to dispose as balloons exist for life of sim + // When the position changes, update the bounds of balloon, direction of movement, and whether or not the the + // balloon is touching an object. No need to dispose as balloons exist for life of sim. this.positionProperty.link( ( position, oldPosition ) => { this.bounds.setMinMax( position.x, position.y, position.x + this.width, position.y + this.height ); @@ -304,8 +304,16 @@ class BalloonModel { } } ); - // when the balloon is released, reset the timer that indicates when balloon was released - this.isDraggedProperty.link( isDragged => { + this.isDraggedProperty.lazyLink( isDragged => { + + // When the user starts dragging a balloon, set its non-dragging velocity to zero. + if ( isDragged ){ + + // Use new Vector2( 0, 0 ) instead of Vector2.ZERO so equality check won't be thwarted by ImmutableVector2. + this.velocityProperty.set( new Vector2( 0, 0 ) ); + } + + // When the balloon is released, reset the timer that indicates when it was released. if ( !isDragged ) { this.timeSinceRelease = 0; } diff --git a/js/balloons-and-static-electricity/view/BalloonNode.js b/js/balloons-and-static-electricity/view/BalloonNode.js index 63880814..8e7d075e 100644 --- a/js/balloons-and-static-electricity/view/BalloonNode.js +++ b/js/balloons-and-static-electricity/view/BalloonNode.js @@ -220,8 +220,7 @@ class BalloonNode extends Node { model.isDraggedProperty.link( updateAccessibleDescription ); globalModel.showChargesProperty.link( updateAccessibleDescription ); - // @private - the drag handler needs to be updated in a step function, see KeyboardDragHandler for more - // information + // @private - the drag handler needs to be updated in a step function, see KeyboardDragHandler for more information const boundaryUtterance = new Utterance(); this.keyboardDragHandler = new KeyboardDragListener( { downDelta: 0, @@ -320,6 +319,11 @@ class BalloonNode extends Node { grabDragInteraction.reset(); } ); + model.velocityProperty.link( velocity => { + console.log( 'velocity.magnitude = ' + velocity.magnitude ); + } ); + + // Handle a query parameter that adds a line and a marker at the "charge center". This can be useful for debugging. if ( BASEQueryParameters.showBalloonChargeCenter ) { const parentToLocalChargeCenter = this.parentToLocalPoint( model.getChargeCenter() ); this.addChild( new Rectangle( 0, 0, 5, 5, { fill: 'green', center: parentToLocalChargeCenter } ) );