Beispiel #1
0
    private Vector3 GetObstacleDirectllyColliderVector(JSObstacleCollider obstacle, Vector3 start, Vector3 end, float radius)
    {
        crossPoint.Clear();
        Vector3[] obstacleVertexs = new Vector3[4];

        obstacleVertexs [0] = new Vector3(obstacle.SelfCollider.size.x * 0.5f + radius,
                                          0,
                                          obstacle.SelfCollider.size.z * 0.5f + radius);
        obstacleVertexs [1] = new Vector3(obstacle.SelfCollider.size.x * 0.5f + radius,
                                          0,
                                          -obstacle.SelfCollider.size.z * 0.5f - radius);
        obstacleVertexs [2] = new Vector3(-obstacle.SelfCollider.size.x * 0.5f - radius,
                                          0,
                                          -obstacle.SelfCollider.size.z * 0.5f - radius);
        obstacleVertexs [3] = new Vector3(-obstacle.SelfCollider.size.x * 0.5f - radius,
                                          0,
                                          obstacle.SelfCollider.size.z * 0.5f + radius);

        obstacleVertexs [0] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [0]);
        obstacleVertexs [1] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [1]);
        obstacleVertexs [2] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [2]);
        obstacleVertexs [3] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [3]);

        for (int i = 0; i < obstacleVertexs.Length; ++i)
        {
            JSHelper.DebugDrawLine(obstacleVertexs [i % 4], obstacleVertexs [(i + 1) % 4], Color.yellow, 5.0f);
            CrossPoint(start, end, obstacleVertexs [i % 4], obstacleVertexs [(i + 1) % 4], start.y);
        }

        if (crossPoint.Count > 0)
        {
            Vector3 closestPoint = crossPoint [0];
            if (crossPoint.Count > 1)
            {
                float closestDistance = Vector3.Distance(start, crossPoint [0]);
                for (int i = 1; i < crossPoint.Count; ++i)
                {
                    if (Vector3.Distance(start, crossPoint [i]) < closestDistance)
                    {
                        closestDistance = Vector3.Distance(start, crossPoint [i]);
                        closestPoint    = crossPoint [i];
                    }
                }
            }
            return(closestPoint);
        }

        return(end);
    }
Beispiel #2
0
    private Vector3 ClosestVectorBetweenCharacterAndObstacle(JSCharacterCollider character, JSObstacleCollider obstacle, Vector3 start, float radius, List <Vector3> vectorInDirection)
    {
        Vector3[] obstacleVertexs = new Vector3[4];
        Vector3   closestVector   = Vector3.zero;
        float     closestDistance = 0;
        float     vectorDistance  = 0;

        obstacleVertexs [0] = new Vector3(obstacle.SelfCollider.size.x * 0.5f + radius,
//			obstacle.ColliderCenterTransform.position.y - start.y,
                                          0,
                                          obstacle.SelfCollider.size.z * 0.5f + radius);
        obstacleVertexs [1] = new Vector3(obstacle.SelfCollider.size.x * 0.5f + radius,
//			obstacle.ColliderCenterTransform.position.y - start.y,
                                          0,
                                          -obstacle.SelfCollider.size.z * 0.5f - radius);
        obstacleVertexs [2] = new Vector3(-obstacle.SelfCollider.size.x * 0.5f - radius,
//			obstacle.ColliderCenterTransform.position.y - start.y,
                                          0,
                                          obstacle.SelfCollider.size.z * 0.5f + radius);
        obstacleVertexs [3] = new Vector3(-obstacle.SelfCollider.size.x * 0.5f - radius,
//			obstacle.ColliderCenterTransform.position.y - start.y,
                                          0,
                                          -obstacle.SelfCollider.size.z * 0.5f - radius);

        obstacleVertexs [0] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [0]);
        obstacleVertexs [1] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [1]);
        obstacleVertexs [2] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [2]);
        obstacleVertexs [3] = obstacle.ColliderCenterTransform.TransformPoint(obstacleVertexs [3]);

        for (int i = 0; i < obstacleVertexs.Length; ++i)
        {
            if (!vectorInDirection.Contains(obstacleVertexs [i]))
            {
                closestVector = obstacleVertexs [i];
                break;
            }
        }
        closestDistance = Vector3.Distance(start, closestVector);
        vectorDistance  = 0;
        for (int i = 0; i < obstacleVertexs.Length; ++i)
        {
            if (!vectorInDirection.Contains(obstacleVertexs [i]) &&
                CheckColliderVector(obstacleVertexs [i], character.SelfCollider.bounds.size))
            {
                vectorDistance = Vector3.Distance(start, obstacleVertexs [i]);
                if (vectorDistance < closestDistance)
                {
                    closestDistance = vectorDistance;
                    closestVector   = obstacleVertexs [i];
                }
            }
        }

        return(closestVector);
    }