Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


bouncing vectors

This topic is 5932 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

i found an artickle on gamasutra: http://www.gamasutra.com/features/20020118/vandenhuevel_01.htm which has a nice algirithm in the end calculating the resulting vectors after a collision. I implemented this and it looks great. However when i looked at it more carefully (by mistake?) i realised that the sum of the lengths of the vectors before the collision was not the same as the sum of the length of the vectors after, even when the masses of the objects are the same - in most cases. When one object stood still and another collided with this object STRAIGHT (0 degrees) it worked. Can anyone explain what does this? is it my code?

        double totalLength1 = m_velocity.length() + enemy.m_velocity.length();
        Vector n;
        n.set(m_x - enemy.m_x, m_y - enemy.m_y);
        double a1 = m_velocity.dot(n);
        double a2 = enemy.m_velocity.dot(n);
        double optimizedP = (2.0 * (a1 - a2)) / (m_mass + enemy.m_mass);

        Vector v1_ = m_velocity - optimizedP * enemy.m_mass * n;

        Vector v2_ = enemy.m_velocity + optimizedP * m_mass * n;
        m_velocity = v1_;
        enemy.m_velocity = v2_;    

        double totalLength2 = m_velocity.length() + enemy.m_velocity.length();

        printf("%f, %f\n", totalLength1, totalLength2);

thanks for any help zilch_

Share this post

Link to post
Share on other sites
Can it be that the formula optimisedP is not 100% accurate when it comes to small numbers like this?


Share this post

Link to post
Share on other sites
Forgot to mention that it differs by about 1% ... and i use very small vectors... but still; I use doubles... and small numbers shouldn''t be a problem

well well

sorry if i "spam"


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!