# Vector Projection...Why does this work???

This topic is 3217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Been trying to work out where i am going wrong, projecting one vector onto another does not work unless i half the dot product, why? this is the formula i am using....projectionVector = (V dot N) * N, where N = the projection normal, V = the vector being projected. ...currently i have this line.... m_vPointOfContact = m_vPos + (m_vShotDir * (fDotProd*.5f)); ...and that works...but shouldn't it be just this... m_vPointOfContact = m_vPos + (m_vShotDir * fDotProd);

// m_vShotDir is a normalized vector in the direction you are going to shoot.

//  dir to obj
Vector3 vDirToObj = vObjPos - m_vPos;

//  now project the vector to the obj
float fDotProd = m_vShotDir.Dot(vDirToObj);
m_vPointOfContact = m_vPos + (m_vShotDir * (fDotProd*.5f));



##### Share on other sites
(V dot N) * N will project V on to N, but if N is not unit length it will also scale V, which I think is the problem you're seeing.

##### Share on other sites
Thats it!, i initialized m_vShotDir to m_vShotDir.x = 1.0f and m_vShotDir.y = 1.0f, thinking that that would make it a 45 degree angle.
Am calculating m_vShotDir now, by normalizing the vector from m_vPos to the shot destination. that fixed it. thanks!

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009481
• ### Who's Online (See full list)

There are no registered users currently online

×