Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 1246 bytes modified
parent
9f656ce066
commit
0e9c66e63c
|
@ -0,0 +1,173 @@
|
|||
if (data.entity === this.parentEntity) {
|
||||
console.log('AR Football 2 Entity Loaded');
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code Components
|
||||
*/
|
||||
this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun');
|
||||
this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l');
|
||||
|
||||
/**
|
||||
* Meshes
|
||||
*/
|
||||
this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s');
|
||||
this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2');
|
||||
|
||||
/**
|
||||
* Geometry
|
||||
*/
|
||||
this.ballGeometry = R3.EntityManager.Instance.findComponentById('dt6jl8kocw');
|
||||
|
||||
/**
|
||||
* Materials
|
||||
*/
|
||||
this.materialWhite = R3.EntityManager.Instance.findComponentById('iualutcl1y');
|
||||
this.materialBlack = R3.EntityManager.Instance.findComponentById('2g36po454g');
|
||||
|
||||
this.playerRotation = {
|
||||
x : 0,
|
||||
y : 0
|
||||
};
|
||||
|
||||
this.kick = {
|
||||
start : null,
|
||||
distance : 0,
|
||||
time : 0,
|
||||
speed : 0,
|
||||
direction : 0
|
||||
};
|
||||
|
||||
this.balls = [];
|
||||
|
||||
this.activeBall = this.football.instance;
|
||||
|
||||
R3.CustomCode.prototype.move = function(data) {
|
||||
|
||||
var x = data.x;
|
||||
var y = data.y;
|
||||
|
||||
if (data.source === 'mouse' || 'touch') {
|
||||
x *= 0.01;
|
||||
y *= 0.01;
|
||||
}
|
||||
|
||||
this.playerRotation.x += x;
|
||||
this.playerRotation.y += y;
|
||||
|
||||
var kick = false;
|
||||
|
||||
var canKick = false;
|
||||
|
||||
if (this.playerRotation.y > Math.PI) {
|
||||
canKick = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp player rotation to values between 0 and 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp direction angle between 0 and Math.PI * 2
|
||||
*/
|
||||
if (this.playerRotation.x > Math.PI * 2) {
|
||||
this.playerRotation.x -= Math.PI * 2;
|
||||
}
|
||||
|
||||
if (this.playerRotation.x < 0) {
|
||||
this.playerRotation.x += Math.PI * 2;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (kick) {
|
||||
|
||||
if (this.kick.start === null) {
|
||||
console.warn('no kick start time');
|
||||
return;
|
||||
}
|
||||
|
||||
this.kick.time = Date.now() - this.kick.start;
|
||||
|
||||
this.kick.speed = this.kick.distance / this.kick.time;
|
||||
|
||||
this.kick.direction = this.playerRotation.x;
|
||||
|
||||
this.balls.push(this.activeBall);
|
||||
|
||||
this.activeBall = null;
|
||||
|
||||
console.log('kick', this.kick);
|
||||
}
|
||||
|
||||
if (canKick && this.activeBall === null) {
|
||||
|
||||
console.log('can kick');
|
||||
|
||||
this.activeBall = new THREE.Mesh(
|
||||
this.ballGeometry.instance,
|
||||
[
|
||||
this.materialWhite.instance,
|
||||
this.materialBlack.instance
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (y > 0 && canKick) {
|
||||
|
||||
if (this.kick.start === null) {
|
||||
this.kick.start = Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moving down, record the distance travelled
|
||||
*/
|
||||
this.kick.distance += Math.abs(y);
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
|
||||
/**
|
||||
* We are no longer moving down, also reset our Y distance counter
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.kick = {
|
||||
start : null,
|
||||
distance : 0,
|
||||
time : 0,
|
||||
speed : 0,
|
||||
direction : 0
|
||||
};
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
|
||||
this.mouseMove.entityLoaded = this;
|
||||
this.touchMove.entityLoaded = this;
|
||||
|
||||
//@ sourceURL=entityLoaded.js
|
Loading…
Reference in New Issue