Пример #1
0
    void AddObstacle()
    {
        ObstacleHelper group = target as ObstacleHelper;

        if (group == null)
        {
            return;
        }
        int        count = group.transform.childCount;
        GameObject go    = new GameObject(string.Format("{0}", count + 1));
        //go.AddComponent<BoxCollider>();
        //Rigidbody rigidbody=go.AddComponent<Rigidbody>();
        //rigidbody.useGravity = false;
        //rigidbody.constraints = RigidbodyConstraints.FreezeAll;
        //go.layer = LayerMask.NameToLayer("Interactive");
        RVOSquareObstacle rvo = go.AddComponent <RVOSquareObstacle>();

        rvo.obstacleMode = RVOSquareObstacle.ObstacleVertexWinding.KeepOut;
        rvo.center       = Vector2.zero;
        GameObject herostart = GameObject.Find("HeroStart");

        go.transform.parent        = group.transform;
        go.transform.localPosition = herostart.transform.localPosition;
        go.AddComponent <SceneObstacleFxLength>();

        GameObject obstacle_anchor = new GameObject("anchor");

        obstacle_anchor.transform.parent        = go.transform;
        obstacle_anchor.transform.localPosition = Vector3.zero;
    }
 public void MovePlayer(int moveX, int moveY)
 {
     if (ObstacleHelper.CheckForObstacles(_body.transform.position, ((_body.transform.forward * moveY) + (_body.transform.right * -moveX)), 0.4f))
     {
         transform.Translate(moveY * _body.transform.forward * Time.deltaTime * movementSpeed);
         transform.Translate(-moveX * _body.transform.right * Time.deltaTime * movementSpeed);
     }
 }
Пример #3
0
    void DispearObstacle()
    {
        ObstacleHelper group = target as ObstacleHelper;

        if (group == null)
        {
            return;
        }
        group.DispearObstacle();
    }
Пример #4
0
    void ShowObstacle()
    {
        ObstacleHelper group = target as ObstacleHelper;

        if (group == null)
        {
            return;
        }
        group.ShowObstacle(m_group);
    }
Пример #5
0
    public bool FoundPath(Vector2 checkFromPosition, Vector2 checkToPosition, Vector2 moveDirection)
    {
        var obstacle = ObstacleHelper.GetObstacle(checkFromPosition, checkToPosition);

        if (BoundaryHelper.ContainedInObstacleCollider(checkToPosition) || BoundaryHelper.TargetLocationEndsInsideObstacle(checkToPosition))
        {
            checkToPosition = BoundaryHelper.FindPositionThroughObstacle(checkToPosition, checkFromPosition);
        }

        checkToPosition += moveDirection * 5f;

        if (obstacle == null)
        {
            return(false);
        }

        TargetLocationOnceFinishedWithObstaclePath = checkToPosition;
        PointBeforeStartingObstaclePath            = checkFromPosition;

        var adjustedPointToCheckClosestToStart = checkFromPosition;

        var closestPointToStart = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToStart);

        while (closestPointToStart == null)
        {
            adjustedPointToCheckClosestToStart += moveDirection * StepTowardsObstacleSide;

            closestPointToStart = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToStart);
        }

        var adjustedPointToCheckClosestToEnd = checkToPosition;

        var closestPointToEnd = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToEnd);

        while (closestPointToEnd == null)
        {
            adjustedPointToCheckClosestToEnd -= moveDirection * StepTowardsObstacleSide;

            closestPointToEnd = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToEnd);
        }

        _currentObstaclePath = obstacle.BestPath(closestPointToStart, closestPointToEnd, checkToPosition);

        return(_currentObstaclePath != null && _currentObstaclePath.Count > 0);
    }
Пример #6
0
    public void Jump()
    {
        GameObject obstacle = ObstacleHelper.ReturnObstacle(_body.transform.position, _body.transform.forward, 0.4f);

        if (obstacle != null)
        {
            if (_body.transform.position.y > obstacle.transform.position.y)
            {
                GrabLedge(obstacle);
                return;
            }
        }

        if (!isJumping)
        {
            isJumping = true;
            GetComponent <Rigidbody>().velocity = Vector3.Lerp(_body.transform.position, Vector3.up * jumpHeight, 1);
        }
    }
Пример #7
0
 void OnDestroy()
 {
     m_Instance = null;
 }
Пример #8
0
 void Awake()
 {
     m_Instance = this;
 }