For my Maths unit at college, now we have to manually calculate if a sphere is colliding with a capsule collider.
The knowledge I’ve to go along with is that this;
You may have the next Sphere:
- LadyBird3 – CentrePoint = (0, 0, 0), Radius = 18.0
And the next capsule
- Sanic – BottomPoint = (0,2,6), TopPoint = (0, 12, 6), Radius = 5.0
Decide if the next pair-wise collision happens:
Sanic & LadyBird3
In our lecture, we’re informed the next;
NOTE: Normalizing at this step is unimportant
First, we’re going to verify the Dot Product of AC and AB
-
If this Dot Product is lower than 0, meaning the closest level from the road phase to C is A
-
So we are able to simply return the squared size of AC and cease any additional calculations
-
Now we carry out the identical check with the Dot Product of BA and BC
-
As soon as once more, if the Dot Product is lower than 0, B can be the closest level on the road phase to C, so we might simply return the size of BC and cease any additional calculations.
Projection…
If the dot product returned > 0 for each factors of the road phase, we have to undertaking C onto AB to get the space.
There’s an environment friendly method to get the squared distance if that is all we care about:
-
SquaredDistance = AC.LengthSq – (AC . AB) * (AC . AB) / AB.LengthSq
-
When performing the dot product right here, we have to guarantee that it’s NOT normalized.
And the ultimate step is to make use of this squared distance and examine it to the sum of each radii squared to find out if there may be an intersection.
So, I am making an attempt to calculate if they’re intersecting or not utilizing the knowledge from above.
All I’ve managed to give you is that this
(Taking away the LadyBird3 positions from Sanics place (TP, BP))
AC = (0, 2, 6)
AB = (0, -10, 0)
Dot Product = -20
BA = (0, 10, 0)
BC = (0, 12, 6)
Dot Product = 120
It appears like with the values I am getting aren’t appropriate, or the method I am doing is unsuitable… Is anybody in a position to level me in the suitable path?


