Find the distance between a point inside the volume of the capsule and the lower border of the capsule below that point.
I am creating a levitating character. I need it to float gently above the ground at a certain height. I find the ground using Physics.CapsuleCast and raise the character to a certain height above the ground.
The problem is that due to the characteristic shape of the bottom of the capsule, if the character touches the ground not with the center, but with the edge of the capsule, standing on a steep ramp or step, then this point is slightly higher than the lowest point of the bottom of the capsule. I raise the character by the difference between the bottom point of the capsule and the found height of the ground. It turns out that I raise it higher than necessary and the character falls and rises endlessly. A capsule cast does not have rigid boundaries, like a collider, so the point of contact with the ground can be anywhere within the volume of a capsule cast.
I need to find a specific distance between the point of contact with the ground somewhere inside the volume of the capsule and the border of the capsule vertically below this point - this will be the height to which i need to raise the character. How can I calculate this distance? I only have the ground contact position and the characteristics of the capsule cast: the position of the lower edge of the capsule, its width, the radius of the capsule hemispheres, the center of the capsule hemispheres, etc.
Probably there is some simple formula or something like that?
Your answer
Follow this Question
Related Questions
Correct and efficient player detection? 1 Answer
How can I make character accelerate and deccelerate using GetAxis? 0 Answers
Raycast on Character Controller is...inset? 0 Answers
Help apdapting character flip script to use GetComponent().flip = true; 2 Answers
Character Controller moves slow? 0 Answers