![]() The check we do is to check that the distance isn't 0. I would also recommend you learn vectors. That is what games tend to use most often. If you are interested in learning more, look at the impulse method. You should find a lot of info about it online. This is called the penalty method for collision response. But in practice this ends up quite unstable, so we use a smaller value instead. A value of 1 would represent a perfectly stuff collision. K is a constant used to change how 'hard' the spring is. ![]() That last equation is similar to the spring equation, or hooks law.īasically we apply a force in the direction (nx, ny) proposal to how 'deep' the collision is. The actual distance between the ball and circle doesn't matter. We do that because we care about the direction to apply the force in. Making a vector have a length of one means it now only represents the direction, and we loose the length component of the vector. (x/x =1 right? Here it's the same but we do it along X and y separately). Yes, that is the Pythagorean theorem! Exactly right! We use it the get the actual distance from ball to circle.īy dividing (nx, ny) by its length, we get a new vector with a length of 1. A vector is a direction and distance, but represented and the distance along X axis, and distance along Y axis. (nx, ny) is a vector that represents the direction and distance from the ball to the circle. So yes, we are in essence calculating the distance to the ball along the X, and the Y axis separately.
0 Comments
Leave a Reply. |