Skip to content

Commit

Permalink
correct position after attachment rather than freefall position, add …
Browse files Browse the repository at this point in the history
…assertion, see #172
  • Loading branch information
jessegreenberg committed Jan 8, 2020
1 parent 918bf3b commit 8751bfa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/energy-skate-park/common/model/EnergySkateParkModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ define( require => {
// Sometimes (depending on dt) the thermal energy can go negative by the above calculation, see #141
// In that case, set the thermal energy to zero and reduce the speed to compensate.
if ( newThermalEnergy < skaterState.thermalEnergy ) {
const correctedState = this.correctThermalEnergy( skaterState, segment, proposedPosition );
const correctedState = this.correctThermalEnergy( skaterState, segment, newPosition );

newThermalEnergy = correctedState.thermalEnergy;
newSpeed = correctedState.getSpeed();
Expand Down Expand Up @@ -820,7 +820,9 @@ define( require => {
parametricSpeed = parametricSpeed * -1;
}

return skaterState.attachToTrack( newThermalEnergy, track, onTopSideOfTrack, parametricPosition, parametricSpeed, newVelocity.x, newVelocity.y, newPosition.x, newPosition.y );
const attachedSkater = skaterState.attachToTrack( newThermalEnergy, track, onTopSideOfTrack, parametricPosition, parametricSpeed, newVelocity.x, newVelocity.y, newPosition.x, newPosition.y );
assert && assert( Utils.equalsEpsilon( attachedSkater.getTotalEnergy(), skaterState.getTotalEnergy(), 1E-8 ), 'large energy change after attaching to track' );
return attachedSkater;
}

// It just continued in free fall
Expand Down

0 comments on commit 8751bfa

Please sign in to comment.