253 lines
5.8 KiB
JavaScript
253 lines
5.8 KiB
JavaScript
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');
|
|
this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf');
|
|
|
|
/**
|
|
* 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.balls = [];
|
|
|
|
this.activeBall = this.football.instance;
|
|
|
|
this.canKick = false;
|
|
|
|
this.kick = false;
|
|
|
|
this.startTime = null;
|
|
|
|
this.kickDuration = 0;
|
|
|
|
this.kickDistance = 0;
|
|
|
|
R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) {
|
|
|
|
|
|
|
|
};
|
|
|
|
R3.CustomCode.prototype.render = function(delta) {
|
|
|
|
this.balls.map(
|
|
|
|
function(ball) {
|
|
|
|
ball.t += delta;
|
|
|
|
var u = new THREE.Vector3(
|
|
ball.speed * Math.sin(ball.directionAngle),
|
|
ball.speed * Math.sin(ball.upAngle),
|
|
ball.speed * Math.cos(ball.directionAngle)
|
|
);
|
|
|
|
ball.mesh.position.x = ball.s0.x + u.x * ball.t;
|
|
ball.mesh.position.y = ball.s0.y + u.y * ball.t + 0.5 * (-9.8) * ball.t * ball.t;
|
|
ball.mesh.position.z = ball.s0.z + u.z * ball.t;
|
|
|
|
if (ball.mesh.position.y <= 0) {
|
|
ball.s0.x = ball.mesh.position.x;
|
|
ball.s0.y = 0;
|
|
ball.s0.z = ball.mesh.position.z;
|
|
ball.upAngle *= ball.bounciness;
|
|
ball.t = 0;
|
|
}
|
|
|
|
var v = new THREE.Vector3(
|
|
-ball.v.z,
|
|
0,
|
|
ball.v.x
|
|
);
|
|
|
|
|
|
ball.mesh.rotateOnAxis(v.normalize(), -0.2);
|
|
|
|
//object.ball.translateOnAxis(object.v, 1);
|
|
|
|
//object.ball.position.y = object.ball.position.y + 0.5 * (-9.8) * object.t * object.t;
|
|
|
|
|
|
}.bind(this)
|
|
)
|
|
};
|
|
|
|
R3.CustomCode.prototype.move = function(data) {
|
|
|
|
var x = data.x;
|
|
var y = data.y;
|
|
|
|
if (data.source === 'mouse' || 'touch') {
|
|
x *= 0.0025;
|
|
y *= 0.0075;
|
|
}
|
|
|
|
this.playerRotation.x += x;
|
|
this.playerRotation.y += y;
|
|
|
|
/**
|
|
* Clamp player rotation to values between 0 and Math.PI * 2
|
|
*/
|
|
if (this.playerRotation.y > Math.PI) {
|
|
this.playerRotation.y = Math.PI;
|
|
}
|
|
|
|
if (this.playerRotation.y < -Math.PI) {
|
|
this.playerRotation.y = -Math.PI;
|
|
}
|
|
|
|
if (this.playerRotation.x > Math.PI / 2) {
|
|
this.playerRotation.x = Math.PI / 2;
|
|
}
|
|
|
|
if (this.playerRotation.x < -Math.PI / 2) {
|
|
this.playerRotation.x = -Math.PI / 2;
|
|
}
|
|
|
|
if (this.playerRotation.y <= 0) {
|
|
this.canKick = true;
|
|
}
|
|
|
|
if (this.canKick && this.playerRotation.y > 0) {
|
|
this.canKick = false;
|
|
this.kick = true;
|
|
}
|
|
|
|
if (y > 0 && this.canKick) {
|
|
|
|
/**
|
|
* Moving down, initialize start time and record the distance travelled
|
|
*/
|
|
if (this.startTime === null) {
|
|
this.startTime = Date.now();
|
|
}
|
|
|
|
this.kickDistance += Math.abs(y);
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
/**
|
|
* We are no longer moving down, also reset our Y distance counter
|
|
* @type {boolean}
|
|
*/
|
|
this.kickDistance = 0;
|
|
this.startTime = null;
|
|
}
|
|
|
|
|
|
if (this.canKick && this.activeBall === null) {
|
|
|
|
console.log('can kick - creating new ball');
|
|
|
|
this.activeBall = new THREE.Mesh(
|
|
this.ballGeometry.instance,
|
|
[
|
|
this.materialWhite.instance,
|
|
this.materialBlack.instance
|
|
]
|
|
);
|
|
|
|
this.activeBall.scale.copy(this.football.instance.scale);
|
|
|
|
this.football.parentScene.instance.add(this.activeBall);
|
|
}
|
|
|
|
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.3);
|
|
|
|
this.footballPlayer.instance.rotateX(this.playerRotation.y);
|
|
|
|
if (this.kick) {
|
|
|
|
this.kick = false;
|
|
|
|
if (this.startTime === null) {
|
|
console.warn('no kick start time');
|
|
return;
|
|
}
|
|
|
|
var kickDuration = Date.now() - this.startTime;
|
|
|
|
var speed = this.kickDistance / kickDuration * 20;
|
|
|
|
// if (speed > 1.5) {
|
|
// speed = 1.5;
|
|
// }
|
|
|
|
console.log(speed);
|
|
|
|
var v = new THREE.Vector3(0, 0, -1);
|
|
|
|
v.multiplyScalar(speed);
|
|
|
|
v.applyAxisAngle(
|
|
new THREE.Vector3(0,1,0),
|
|
this.playerRotation.x
|
|
);
|
|
|
|
this.balls.push(
|
|
{
|
|
mesh : this.activeBall,
|
|
speed : 8,
|
|
mouseYTravelDistance : this.kick.distance,
|
|
directionAngle : this.playerRotation.x + Math.PI,
|
|
kickDuration : this.kickDuration,
|
|
kickDistance : this.kickDistance,
|
|
kickSpeed : speed,
|
|
upAngle : Math.PI * speed,
|
|
v : v,
|
|
t : 0,
|
|
s0 : new THREE.Vector3(0,0,0),
|
|
bounciness : 0.5
|
|
}
|
|
);
|
|
|
|
this.activeBall = null;
|
|
}
|
|
|
|
|
|
|
|
|
|
}.bind(this)
|
|
|
|
this.mouseMove.entityLoaded = this;
|
|
this.touchMove.entityLoaded = this;
|
|
this.beforeRender.entityLoaded = this;
|
|
|
|
//@ sourceURL=entityLoaded.js
|