nice kicking

beta.r3js.org
-=yb4f310 2018-05-20 13:36:43 +02:00
parent a2e4bfff3d
commit b17e28f8bb
1 changed files with 63 additions and 11 deletions

View File

@ -45,15 +45,53 @@ this.balls = [];
this.activeBall = this.football.instance;
R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) {
};
R3.CustomCode.prototype.render = function(delta) {
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.speed = this.kick.distance / this.kick.time;
this.kick.speed = this.kick.distance / this.kick.time * 40;
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);
v.multiplyScalar(this.kick.speed);
@ -142,20 +186,26 @@ R3.CustomCode.prototype.move = function(data) {
this.balls.push(
{
ball : this.activeBall,
kick : this.kick,
v : v
mesh : this.activeBall,
speed : 6,
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;
console.log('kick', this.kick);
//console.log('kick', this.kick);
}
if (canKick && this.activeBall === null) {
console.log('can kick');
//console.log('can kick');
this.activeBall = new THREE.Mesh(
this.ballGeometry.instance,
@ -181,6 +231,8 @@ R3.CustomCode.prototype.move = function(data) {
* Moving down, record the distance travelled
*/
this.kick.distance += Math.abs(y);
//console.log(this.kick.distance);
}
if (y < 0) {