What is wrong with my Dot Product?

Posted by Clay Ellis Murray on Game Development See other posts from Game Development or by Clay Ellis Murray
Published on 2012-06-30T20:43:33Z Indexed on 2012/07/01 9:24 UTC
Read the original article Hit count: 421

Filed under:
|

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

© Game Development or respective owner

Related posts about JavaScript

Related posts about 2d-physics