2018-05-17 12:42:33 +02:00
|
|
|
if (data.entity === this.parentEntity) {
|
|
|
|
console.log('AR Football 2 Entity Loaded');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code Components
|
|
|
|
*/
|
|
|
|
this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun');
|
2018-05-17 15:37:56 +02:00
|
|
|
this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l');
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meshes
|
|
|
|
*/
|
|
|
|
this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s');
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
this.movingAverage = R3.Utils.MovingAverage(10);
|
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
this.playerRotation = {
|
|
|
|
x : 0,
|
|
|
|
y : 0
|
|
|
|
};
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
|
|
|
|
R3.CustomCode.prototype.kick = function(data) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
R3.CustomCode.prototype.move = function(data) {
|
|
|
|
|
|
|
|
var x = data.x;
|
|
|
|
var y = data.y;
|
2018-05-17 15:37:56 +02:00
|
|
|
var speed = 0;
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (data.source === 'mouse' || 'touch') {
|
2018-05-17 12:42:33 +02:00
|
|
|
x *= 0.01;
|
|
|
|
y *= 0.01;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.playerRotation.x += x;
|
|
|
|
this.playerRotation.y += y;
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
this.timestamp = null;
|
|
|
|
|
|
|
|
var kick = false;
|
|
|
|
|
|
|
|
var canKick = false;
|
|
|
|
|
|
|
|
var movingDown = false;
|
|
|
|
|
|
|
|
if (this.playerRotation.y > Math.PI) {
|
|
|
|
canKick = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clamp player rotation to values between Math.PI * 2
|
|
|
|
*/
|
|
|
|
if (this.playerRotation.y > Math.PI * 2) {
|
|
|
|
this.playerRotation.y -= Math.PI * 2;
|
|
|
|
kick = true;
|
|
|
|
canKick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.playerRotation.y < 0) {
|
|
|
|
this.playerRotation.y += Math.PI * 2;
|
|
|
|
canKick = true;
|
|
|
|
}
|
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
this.footballPlayer.instance.matrix = new THREE.Matrix4();
|
|
|
|
this.footballPlayer.instance.matrix.decompose(
|
|
|
|
this.footballPlayer.instance.position,
|
|
|
|
this.footballPlayer.instance.quaternion,
|
|
|
|
this.footballPlayer.instance.scale
|
|
|
|
);
|
|
|
|
|
|
|
|
this.footballPlayer.instance.translateY(0.78);
|
|
|
|
|
|
|
|
this.footballPlayer.instance.rotateY(this.playerRotation.x);
|
|
|
|
|
|
|
|
this.footballPlayer.instance.translateZ(0.2);
|
|
|
|
|
|
|
|
this.footballPlayer.instance.rotateX(this.playerRotation.y);
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (kick) {
|
|
|
|
console.log('kick');
|
|
|
|
console.log(Number(Date.now()) - Number(this.timestamp));
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (canKick) {
|
|
|
|
console.log('can kick');
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (y > 0 && canKick) {
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (this.movingDown) {
|
|
|
|
/**
|
|
|
|
* Do nothing
|
|
|
|
*/
|
|
|
|
} else {
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
this.timestamp = Date.now();
|
|
|
|
console.log('time stamped : ' + this.timestamp);
|
|
|
|
this.movingDown = true
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
/**
|
|
|
|
* Moving down, record the average
|
|
|
|
*/
|
|
|
|
// speed = this.movingAverage(y);
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (y < 0) {
|
|
|
|
this.movingDown = false;
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}.bind(this)
|
|
|
|
|
|
|
|
this.mouseMove.entityLoaded = this;
|
2018-05-17 15:37:56 +02:00
|
|
|
this.touchMove.entityLoaded = this;
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
//@ sourceURL=entityLoaded.js
|