Ejemplo n.º 1
0
    ParkourEntryPoint CheckParkourStartEntry(Vector3 direction, bool isClimbing)
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, direction, out hit, _parkourCollider.radius, _obstacleMask))
        {
            var parkourObstacle       = _parkourObstacles.Find(obstacle => obstacle.Collider == hit.collider);
            ParkourObstacle.Wall wall = default(ParkourObstacle.Wall);
            if (parkourObstacle != null && parkourObstacle.TryGetWall(hit.point, ref wall))
            {
                return(new ParkourEntryPoint(hit.point, wall, parkourObstacle, isClimbing));
            }
        }
        return(null);
    }
Ejemplo n.º 2
0
    private IEnumerator Climbing(ParkourObstacle obstacle, ParkourObstacle.Wall wall, Vector3 startPoint, Quaternion startRotation)
    {
        Vector3    startPlayerPosition = transform.position;
        Quaternion startPlayerRotation = transform.rotation;
        float      elapsed             = 0f;
        float      translationTime     = Vector3.Distance(startPlayerPosition, startPoint) / _translationVelocity;

        while (elapsed < translationTime)
        {
            transform.position = Vector3.Lerp(startPlayerPosition, startPoint, elapsed / translationTime);
            transform.rotation = Quaternion.Lerp(startPlayerRotation, startRotation, elapsed / translationTime);
            elapsed           += Time.deltaTime;
            yield return(null);
        }
        transform.rotation = startRotation;

        startPlayerPosition = transform.position;
        Vector3 targetUpPosition = new Vector3(transform.position.x,
                                               wall.GetHighestPoint().y + _playerController.CharacterHeight / 2,
                                               transform.position.z);
        Vector3 targetForwardPosition = targetUpPosition + transform.forward * _playerController.CharacterRadius * 2;

        elapsed = 0f;
        float climbTime = Vector3.Distance(startPlayerPosition, targetUpPosition) / _climbVelocity;

        while (elapsed < climbTime)
        {
            transform.position = Vector3.Lerp(startPlayerPosition, targetUpPosition, elapsed / climbTime);
            elapsed           += Time.deltaTime;
            yield return(null);
        }
        float forwardTime = Vector3.Distance(startPlayerPosition, targetForwardPosition) / _forwardVelocity;

        elapsed             = 0f;
        startPlayerPosition = transform.position;
        while (elapsed < forwardTime)
        {
            transform.position = Vector3.Lerp(startPlayerPosition, targetForwardPosition, elapsed / forwardTime);
            elapsed           += Time.deltaTime;
            yield return(null);
        }
        StopClimbing();
    }