Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question 3D Physics.CapsuleCast Centroid?

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

  1. as20311


    Jan 1, 2022
    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


    Jan 1, 2014
    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