How could we hold and move an entity from mobile touch inputs?
I have written following script:
MoveForward.prototype.onTouchMove = function (event) {
//if(MoveForward.canPlay == false) return;
for (var i = 0; i < event.changedTouches.length; i++) {
var touch = event.changedTouches[i];
if (this.touchId == touch.id) {
var pos;
var speed = 0.01;
pos = this.entity.getPosition();
if (touch.x < this.lastTouchPoint.x) {
console.log('Movement left');
pos.x = 5;
}
if (touch.x > this.lastTouchPoint.x) {
console.log('Movement right');
pos.x = -5;
}
this.vec.lerp(this.vec, pos, speed);
this.entity.setPosition(this.vec);
this.lastTouchPoint.set(touch.x, touch.y);
this.timer = 0;
}
}
};