Search Unity

Question 3D Physics.CapsuleCast Centroid?

Discussion in 'Physics' started by as20311, May 26, 2022.

  1. as20311

    as20311

    Joined:
    Jan 1, 2022
    Posts:
    1
    How do I get the centroid for Physics.CapsuleCast? I'm trying to make a kinematic player controller and I can't find anything about how to get the centroid of a RaycastHit, for collisions of course.
     
    gaps likes this.
  2. gaps

    gaps

    Joined:
    Jan 1, 2014
    Posts:
    15
    Bump on this. It seems that the physics 3D is lacking the centroid property (that exists in physics 2D) when box/sphere/capsule casting :(

    You can however calculate it yourself by using this:
    position + direction.normalized * hitInfo.distance


    Note that the short description in the documentation for the RaycastHit is somewhat misleading, as it describes it as "the distance from the ray's origin to the impact point", but the full documentation for the distance property says "In the case of a swept volume or sphere cast, the distance represents the magnitude of the vector from the origin point to the translated point at which the volume contacts the other collider".
     
    Last edited: Mar 20, 2023