Commit 259429a5 authored by DoNaTio s.r.o.'s avatar DoNaTio s.r.o.
Browse files

fix reflection

parent 7f0bc29f
...@@ -65,13 +65,16 @@ function ClientCollision(Ball, Racket, User) { ...@@ -65,13 +65,16 @@ function ClientCollision(Ball, Racket, User) {
vR = racketVector, //vektor rakety vR = racketVector, //vektor rakety
vL = ballVectors; // vektor lopticky vL = ballVectors; // vektor lopticky
var nvR = this.normalize(vR);
var vL2 = this.reflect(vL, nvR);
attributes.ball.setVectors(vL2.x, vL2.y); if (vL.vx == 0 && vL.vy == 0) {
if (vL2.x == 0 && vL2.y == 0) { var nvR = this.normalize(vR);
attributes.ball.setVectors(1, 1); attributes.ball.setVectors(nvR.vx, nvR.vy);
}else{
var nvR = this.normalize(vR);
var vL2 = this.reflect(vL, nvR);
attributes.ball.setVectors(vL2.x, vL2.y);
} }
console.log(ballVectors, 'ball'); console.log(ballVectors, 'ball');
console.log(attributes.racket.getAttributes(), 'getAttributes'); console.log(attributes.racket.getAttributes(), 'getAttributes');
console.log(racketVector, 'racketVector'); console.log(racketVector, 'racketVector');
......
...@@ -50,7 +50,7 @@ function ClientRacket() { ...@@ -50,7 +50,7 @@ function ClientRacket() {
getVector: function () { getVector: function () {
// console.log(attributes.x - attributes.prevX, attributes.y - attributes.prevY, 'lala'); // console.log(attributes.x - attributes.prevX, attributes.y - attributes.prevY, 'lala');
return { return {
vx: attributes.prevX - attributes.x, vx: attributes.x - attributes.prevX,
vy: attributes.y - attributes.prevY vy: attributes.y - attributes.prevY
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment