Exemple #1
0
    bool rayHitSphere(Vector3 from, Vector3 dir, out Vector3 hitPoint, out Vector3 hitNormal)
    {
        var shereWorldCenter = controller.getSphereWorldCenter(); // 先射球
        var R     = SphereTerrain.R;
        var isHit = GeometryTool.RayMarchingSphere(from, dir, shereWorldCenter, R, out hitPoint, out hitNormal);

        if (isHit)
        {
            var tangent = Vector3.zero;
            Vector3.OrthoNormalize(ref hitNormal, ref tangent);
            controller.to.rotation = Quaternion.LookRotation(hitNormal, tangent);
            controller.to.position = hitPoint;
        }
        else
        {
            controller.to.position = from + dir * 1000.0f;
            controller.to.rotation = Quaternion.identity;
        }
        return(isHit);
    }