Ejemplo n.º 1
0
    //将所有路标点的位置投射到一个二维坐标系中。并返回他们在二维坐标系中的坐标
    private WayPointsReal[] CalWayPoint2DCoor(WayPoint.WayPointSequence[] wayPoints, Transform playerPos, int length, float orientation, float routineDistance, Vector3 origin, Vector3 xAxis, Vector3 zAxis)
    {
        int nearestnum = NearestMoveableWayPoint();
        int largerNum, smallerNum;

        if (nearestnum == length - 1)
        {
            largerNum = 0;
        }
        else
        {
            largerNum = nearestnum + 1;
        }
        if (nearestnum == 0)
        {
            smallerNum = length - 1;
        }
        else
        {
            smallerNum = nearestnum - 1;
        }
        int assumedNum = Mathf.CeilToInt(routineDistance) + 1;

        WayPointsReal[] resultWayPoints = new WayPointsReal[assumedNum];
        float           anglelarger     = Vector3.Angle(GeneralVector3.Vector3NoHeight(playerPos.forward), GeneralVector3.Vector3NoHeight(wayPoints[largerNum].transform.position) - GeneralVector3.Vector3NoHeight(playerPos.position));
        float           anglesmaller    = Vector3.Angle(GeneralVector3.Vector3NoHeight(playerPos.forward), GeneralVector3.Vector3NoHeight(wayPoints[smallerNum].transform.position) - GeneralVector3.Vector3NoHeight(playerPos.position));

        if (anglelarger >= anglesmaller)
        {
            int index = smallerNum;
            for (int i = 0; i < assumedNum; ++i)
            {
                resultWayPoints[i].realPosition = GeneralVector3.GetRealPoint(origin, xAxis, zAxis, GeneralVector3.Vector3NoHeight(wayPoints[index].transform.position));
                resultWayPoints[i].turnType     = wayPoints[index].turnType;
                if (index == 0)
                {
                    index = length - 1;
                }
                else
                {
                    --index;
                }
            }
        }
        else
        {
            int index = largerNum;
            for (int i = 0; i < assumedNum; ++i)
            {
                resultWayPoints[i].realPosition = GeneralVector3.GetRealPoint(origin, xAxis, zAxis, GeneralVector3.Vector3NoHeight(wayPoints[index].transform.position));
                resultWayPoints[i].turnType     = wayPoints[index].turnType;
                if (index == length - 1)
                {
                    index = 0;
                }
                else
                {
                    ++index;
                }
            }
        }
        return(resultWayPoints);
    }
Ejemplo n.º 2
0
    //TODO
    //private void MovePlayer()
    //{
    //    int num = NearestMovenableWayPoint();
    //    if (wayPoint.wayPoints[num].turnType == WayPoint.turnType.straight) playerTransform.position = MoveStraight(playerTransform, wayPoint.wayPoints[num].transform);
    //    else if(wayPoint.wayPoints[num].turnType == WayPoint.turnType.ninetyLeft)
    //}

    //Update player position
    private void MovePlayer(Player player)
    {
        int moveIndex = NearestMoveableWayPoint();
        Ray direction = new Ray(GeneralVector3.Vector3NoHeight(player.transform.position), wayPoint.wayPoints[moveIndex].transform.position - GeneralVector3.Vector3NoHeight(player.transform.position));

        //Debug.Log(direction);
        player.transform.position = direction.GetPoint(player.velocity * Time.deltaTime) + new Vector3(0, 0.5f, 0);
    }