I'm working on a small Breakout clone using Cocos2D-JS, without the use of a physics engine.
One of the things that baffles me was how the ball bounces. My friend came up with this:
inputVector - 2(normalVector * inputVector)
I have no idea how to translate that in code. So I tried with this:
g_Ball.position = this.velocityComputer(cc.p(g_Ball.x, g_Ball.y), cc.p(this.x, this.y));
velocityComputer: function(inVector, thisNVector) {
var prodVec = cc.pDot(inVector, thisNVector);
var retVec = inVector - (2 * (prodVec * inVector));
cc.log(retVec);
// cc.log(blockNVec);
return retVec;
},
But g_Ball
doesn't change directions, and retVec
simply logs NaN
.
Any suggestions?
Thanks.
No comments:
Post a Comment