nice kicking
parent
a2e4bfff3d
commit
b17e28f8bb
|
@ -45,15 +45,53 @@ this.balls = [];
|
||||||
|
|
||||||
this.activeBall = this.football.instance;
|
this.activeBall = this.football.instance;
|
||||||
|
|
||||||
|
R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
R3.CustomCode.prototype.render = function(delta) {
|
R3.CustomCode.prototype.render = function(delta) {
|
||||||
|
|
||||||
this.balls.map(
|
this.balls.map(
|
||||||
function(object) {
|
|
||||||
var ball = object.ball;
|
|
||||||
var kick = object.kick;
|
|
||||||
|
|
||||||
ball.translateOnAxis(object.v, 1);
|
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.1);
|
||||||
|
|
||||||
|
//object.ball.translateOnAxis(object.v, 1);
|
||||||
|
|
||||||
|
//object.ball.position.y = object.ball.position.y + 0.5 * (-9.8) * object.t * object.t;
|
||||||
|
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,10 +165,16 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
|
|
||||||
this.kick.time = Date.now() - this.kick.start;
|
this.kick.time = Date.now() - this.kick.start;
|
||||||
|
|
||||||
this.kick.speed = this.kick.distance / this.kick.time;
|
this.kick.speed = this.kick.distance / this.kick.time * 40;
|
||||||
|
|
||||||
this.kick.direction = this.playerRotation.x;
|
this.kick.direction = this.playerRotation.x;
|
||||||
|
|
||||||
|
if (this.kick.speed > 1) {
|
||||||
|
this.kick.speed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(this.kick.speed);
|
||||||
|
|
||||||
var v = new THREE.Vector3(0, 0, -1);
|
var v = new THREE.Vector3(0, 0, -1);
|
||||||
|
|
||||||
v.multiplyScalar(this.kick.speed);
|
v.multiplyScalar(this.kick.speed);
|
||||||
|
@ -142,20 +186,26 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
|
|
||||||
this.balls.push(
|
this.balls.push(
|
||||||
{
|
{
|
||||||
ball : this.activeBall,
|
mesh : this.activeBall,
|
||||||
kick : this.kick,
|
speed : 6,
|
||||||
v : v
|
mouseYTravelDistance : this.kick.distance,
|
||||||
|
directionAngle : this.kick.direction + Math.PI,
|
||||||
|
upAngle : Math.PI * this.kick.speed,
|
||||||
|
v : v,
|
||||||
|
t : 0,
|
||||||
|
s0 : new THREE.Vector3(0,0,0),
|
||||||
|
bounciness : 0.5
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.activeBall = null;
|
this.activeBall = null;
|
||||||
|
|
||||||
console.log('kick', this.kick);
|
//console.log('kick', this.kick);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canKick && this.activeBall === null) {
|
if (canKick && this.activeBall === null) {
|
||||||
|
|
||||||
console.log('can kick');
|
//console.log('can kick');
|
||||||
|
|
||||||
this.activeBall = new THREE.Mesh(
|
this.activeBall = new THREE.Mesh(
|
||||||
this.ballGeometry.instance,
|
this.ballGeometry.instance,
|
||||||
|
@ -181,6 +231,8 @@ R3.CustomCode.prototype.move = function(data) {
|
||||||
* Moving down, record the distance travelled
|
* Moving down, record the distance travelled
|
||||||
*/
|
*/
|
||||||
this.kick.distance += Math.abs(y);
|
this.kick.distance += Math.abs(y);
|
||||||
|
|
||||||
|
//console.log(this.kick.distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
|
|
Loading…
Reference in New Issue