#CapsuleCastCustom explaination required

1 messages · Page 1 of 1 (latest)

modern fractal
#

Hello,
Can someone help me understand what's going on in CapsuleCastCustom :

        public static bool CapsuleCastCustom<T, C>(in T target, float3 point1, float3 point2, float radius, float3 direction, float maxDistance, ref C collector, CollisionFilter filter, QueryInteraction queryInteraction = QueryInteraction.Default)
            where T : unmanaged, ICollidable
            where C : struct, ICollector<ColliderCastHit>
        {
            CapsuleCollider collider = default;

            float3 center = (point1 + point2) / 2;

            CapsuleGeometry geometry = new CapsuleGeometry
            {
                Radius = radius,
                Vertex0 = point1 - center,
                Vertex1 = point2 - center
            };

I don't understand how the CapsuleGeometry is built.
Based on the definition of the fields Vertex0 is "The start position of the capsule's inner line segment." and Vertex1 is "The end position of the capsule's inner line segment.".
A capsule being 2 sphere separated by a cylinder, I understand the "inner line segment" as the height of the cylinder.
So in other words Vertex0 and Vertex1 should be the centers of each spheres.

Given that understanding I don't understand why in the world I would substract the center position in :

            CapsuleGeometry geometry = new CapsuleGeometry
            {
                Radius = radius,
                Vertex0 = point1 - center,
                Vertex1 = point2 - center
            };

fathom dune
#

Subtracting Center would put it in local space right?

modern fractal
#

Let say my capsule center is at 0;1;0 and the height is 2.
Vertex0 should be 0;0.5;0 and Vertex1 should be 0;1.5;0.
So to get the proper Vertex0 from my base position 0;0;0 I need to have point1 = 0;1.5;0
So to get the proper Vertex1 from my base position 0;0;0 I need to have point2 = 0;2.5;0
It seems like basic math but I can't make sense of it...

#

FYI, ChatGPT says the same thing as you :/

#

Bottom line is should I pass as point1 and point2 the centers of each spheres making up the collider...

#

or the extremities of the collider

fathom dune
#

point 1 and point 2 are in world space that define the capsule height

#

Let say my capsule center is at 0;1;0 and the height is 2.
Vertex0 should be 0;0.5;0 and Vertex1 should be 0;1.5;0.
are you assuming a radius of 0.5 here?

#

i don't recall if the vertex include the radius or not tbh

#

i feel like they dont

modern fractal
#

yes radius is 0.5

fathom dune
#

yeah im not really getting your problem

#

So to get the proper Vertex0 from my base position 0;0;0 I need to have point1 = 0;1.5;0
So to get the proper Vertex1 from my base position 0;0;0 I need to have point2 = 0;2.5;0

#

i don't get where this comes from?

#

point1 should be 0,0.5,0 and point2 shoudl be 0,1.5,0

#

why are you changing it?

#

you just pass in your world space positions

#

it gets converted to local space so vertex0 is 0,-0.5, 0 and vertex1 is 0,0.5,0

#

so that the center is 0,0,0

modern fractal
#

Ok, I think I tried to get from Casting from a ColliderCastInput to a CustomColliderCast and got my brain melted...

#

I know you are right, I'm just confusing myself...

#

sorry to bother