Tuesday, September 27, 2011

Interactive Vector

Interactive Vector Class I created to help me visualize the output of my "vector combining" class. The ball physics had problems with balls getting stuck together, and I needed to back them away from each other when this happened. I needed to do this in a non-jarring way, so that it would not be noticeable to the user.

Initially here is what I did:
Balls A and B are intersecting and need to back off from one another. They are both currently moving parallel to each other on the Y-axis. Added normalized vector AB to ball B, and normalized vector BA to ball A so that they would move away from each other AND the effect would not be jarring as to totally change the current direction (parallel on the Y-axis) of the balls.

Problem: This method added ENERGY to the system. And after a few frames,
all of the balls in the system would end up moving at ridiculously fast speeds.

Fix: Add The new vectors, but scale down the resulting vector if it's magnitude is GREATER than the original. In this system, I wasn't really worried about losing velocity, but I am sure it could happen. And... If I find I need something that keeps the magnitude exactly that of the original, not simply capping the magnitude, then I will write that code. Till then, this is good enough.


No comments:

Post a Comment