kicking direction
parent
a3c4cbdf3a
commit
a2e4bfff3d
|
@ -1,2 +1,8 @@
|
||||||
return null;
|
|
||||||
//@ sourceURL=CustomCode (7l8ar325qf).js
|
if (!this.entityLoaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.entityLoaded.render(data.delta);
|
||||||
|
|
||||||
|
//@ sourceURL=beforeRender.js
|
|
@ -11,4 +11,4 @@ this.entityLoaded.move(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//@ sourceURL=mouseMoveARFootball2.js
|
//@ sourceURL=mouseMove.js
|
137
ff0fsum4zx.js
137
ff0fsum4zx.js
|
@ -9,29 +9,58 @@ if (data.entity === this.parentEntity) {
|
||||||
*/
|
*/
|
||||||
this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun');
|
this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun');
|
||||||
this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l');
|
this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l');
|
||||||
|
this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meshes
|
* Meshes
|
||||||
*/
|
*/
|
||||||
this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s');
|
this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s');
|
||||||
|
this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2');
|
||||||
|
|
||||||
this.movingAverage = R3.Utils.MovingAverage(10);
|
/**
|
||||||
|
* 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 = {
|
this.playerRotation = {
|
||||||
x : 0,
|
x : 0,
|
||||||
y : 0
|
y : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.kick = {
|
||||||
|
start : null,
|
||||||
|
distance : 0,
|
||||||
|
time : 0,
|
||||||
|
speed : 0,
|
||||||
|
direction : 0
|
||||||
|
};
|
||||||
|
|
||||||
R3.CustomCode.prototype.kick = function(data) {
|
this.balls = [];
|
||||||
|
|
||||||
|
this.activeBall = this.football.instance;
|
||||||
|
|
||||||
|
R3.CustomCode.prototype.render = function(delta) {
|
||||||
|
|
||||||
|
this.balls.map(
|
||||||
|
function(object) {
|
||||||
|
var ball = object.ball;
|
||||||
|
var kick = object.kick;
|
||||||
|
|
||||||
|
ball.translateOnAxis(object.v, 1);
|
||||||
|
}
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
R3.CustomCode.prototype.move = function(data) {
|
R3.CustomCode.prototype.move = function(data) {
|
||||||
|
|
||||||
var x = data.x;
|
var x = data.x;
|
||||||
var y = data.y;
|
var y = data.y;
|
||||||
var speed = 0;
|
|
||||||
|
|
||||||
if (data.source === 'mouse' || 'touch') {
|
if (data.source === 'mouse' || 'touch') {
|
||||||
x *= 0.01;
|
x *= 0.01;
|
||||||
|
@ -41,20 +70,16 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
this.playerRotation.x += x;
|
this.playerRotation.x += x;
|
||||||
this.playerRotation.y += y;
|
this.playerRotation.y += y;
|
||||||
|
|
||||||
this.timestamp = null;
|
|
||||||
|
|
||||||
var kick = false;
|
var kick = false;
|
||||||
|
|
||||||
var canKick = false;
|
var canKick = false;
|
||||||
|
|
||||||
var movingDown = false;
|
|
||||||
|
|
||||||
if (this.playerRotation.y > Math.PI) {
|
if (this.playerRotation.y > Math.PI) {
|
||||||
canKick = true;
|
canKick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clamp player rotation to values between Math.PI * 2
|
* Clamp player rotation to values between 0 and Math.PI * 2
|
||||||
*/
|
*/
|
||||||
if (this.playerRotation.y > Math.PI * 2) {
|
if (this.playerRotation.y > Math.PI * 2) {
|
||||||
this.playerRotation.y -= Math.PI * 2;
|
this.playerRotation.y -= Math.PI * 2;
|
||||||
|
@ -67,6 +92,17 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
canKick = true;
|
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 = new THREE.Matrix4();
|
||||||
this.footballPlayer.instance.matrix.decompose(
|
this.footballPlayer.instance.matrix.decompose(
|
||||||
this.footballPlayer.instance.position,
|
this.footballPlayer.instance.position,
|
||||||
|
@ -83,44 +119,89 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
this.footballPlayer.instance.rotateX(this.playerRotation.y);
|
this.footballPlayer.instance.rotateX(this.playerRotation.y);
|
||||||
|
|
||||||
if (kick) {
|
if (kick) {
|
||||||
console.log('kick');
|
|
||||||
console.log(Number(Date.now()) - Number(this.timestamp));
|
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;
|
||||||
|
|
||||||
|
var v = new THREE.Vector3(0, 0, -1);
|
||||||
|
|
||||||
|
v.multiplyScalar(this.kick.speed);
|
||||||
|
|
||||||
|
v.applyAxisAngle(
|
||||||
|
new THREE.Vector3(0,1,0),
|
||||||
|
this.kick.direction
|
||||||
|
);
|
||||||
|
|
||||||
|
this.balls.push(
|
||||||
|
{
|
||||||
|
ball : this.activeBall,
|
||||||
|
kick : this.kick,
|
||||||
|
v : v
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.activeBall = null;
|
||||||
|
|
||||||
|
console.log('kick', this.kick);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canKick) {
|
if (canKick && this.activeBall === null) {
|
||||||
console.log('can kick');
|
|
||||||
|
console.log('can kick');
|
||||||
|
|
||||||
|
this.activeBall = new THREE.Mesh(
|
||||||
|
this.ballGeometry.instance,
|
||||||
|
[
|
||||||
|
this.materialWhite.instance,
|
||||||
|
this.materialBlack.instance
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.activeBall.scale.copy(this.football.instance.scale);
|
||||||
|
//this.activeBall.scale.copy(this.football.instance.scale);
|
||||||
|
|
||||||
|
this.football.parentScene.instance.add(this.activeBall);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y > 0 && canKick) {
|
if (y > 0 && canKick) {
|
||||||
|
|
||||||
|
if (this.kick.start === null) {
|
||||||
|
this.kick.start = Date.now();
|
||||||
if (this.movingDown) {
|
|
||||||
/**
|
|
||||||
* Do nothing
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.timestamp = Date.now();
|
|
||||||
console.log('time stamped : ' + this.timestamp);
|
|
||||||
this.movingDown = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moving down, record the average
|
* Moving down, record the distance travelled
|
||||||
*/
|
*/
|
||||||
// speed = this.movingAverage(y);
|
this.kick.distance += Math.abs(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
this.movingDown = false;
|
|
||||||
|
/**
|
||||||
|
* 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)
|
}.bind(this)
|
||||||
|
|
||||||
this.mouseMove.entityLoaded = this;
|
this.mouseMove.entityLoaded = this;
|
||||||
this.touchMove.entityLoaded = this;
|
this.touchMove.entityLoaded = this;
|
||||||
|
this.beforeRender.entityLoaded = this;
|
||||||
|
|
||||||
//@ sourceURL=entityLoaded.js
|
//@ sourceURL=entityLoaded.js
|
|
@ -6,8 +6,8 @@ if (!this.entityLoaded) {
|
||||||
this.entityLoaded.move(
|
this.entityLoaded.move(
|
||||||
{
|
{
|
||||||
source : 'touch',
|
source : 'touch',
|
||||||
x : data.meta.totalRight - data.meta.totalLeft,
|
x : data.meta.movementX,
|
||||||
y : data.meta.totalDown - data.meta.totalUp
|
y : data.meta.movementY
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue