Pointer - Reset Velocity on Touch Start (PrevPosition Issue)

Hi all. I have found a conflict trying to use the pointer.velocity property, which calculates pointer speed (movement velocity) based on prevPosition and position.

The problem is that prevPosition is set to whatever the last touched point is on the device. When you lift up finger and then touch down again at another area on the screen, the velocity will be very high as it calculates based on the previous position instead of beginning anew from the current touch point.

Since these are read only properties I cannot reset prevPosition on my own. Ideally I’d set that to equal the current position on touch down, and then calculate velocity after that point.

Any thoughts?

EDIT: In review of Phaser source code, it appears that this is due to the (touch device) pointer’s midPoint values not being reset on touch down. This coupled with the smooth interpolation leads to an error in velocity. Setting this.midPoint to current touch location in touchStart resolves it.

:wave:

I’m not sure what’s correct here. Maybe @rich can opine or you could open an issue for it.

1 Like