Fix bug in accelerateFromAngle, and add comment #1833
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Sorry I sent the previous version of this suggestion to the wrong branch, hopefully this is ok…)
The accelerateFromAngle function has a problem in that if sine or cosine of the angle is negative, then the maximum velocity will end up being negative, which it's never supposed to be.
For example, If your current velocity was 10, and you wanted a limit of 100; depending on the angle of rotation you can suddenly end up with a maximum velocity of -100. This makes your velocity of 10 look to be 110 over the maximum. Then you get an extreme change of velocity. In the app I was working on I ended up with a constant oscillation between -100 and +100 from one frame to the next. Adding the Math.abs functions inside accelerateFromAngle, fixes this.