What is wrong with my Dot Product? [Javascript]
- by Clay Ellis Murray
I am trying to make a pong game but I wanted to use dot products to do the collisions with the paddles, however whenever I make a dot product objects it never changes much from .9 this is my code to make vectors
vector = {
make:function(object){
return [object.x + object.width/2,object.y + object.height/2]
},
normalize:function(v){
var length = Math.sqrt(v[0] * v[0] + v[1] * v[1])
v[0] = v[0]/length
v[1] = v[1]/length
return v
},
dot:function(v1,v2){
return v1[0] * v2[0] + v1[1] * v2[1]
}
}
and this is where I am calculating the dot in my code
vector1 = vector.normalize(vector.make(ball))
vector2 = vector.normalize(vector.make(object))
dot = vector.dot(vector1,vector2)
Here is a JsFiddle of my code currently the paddles don't move.
Any help would be greatly appreciated