• Advertisement
Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
(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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement