Exemplo n.º 1
0
    void Start()
    {
        if (UseFixedAspectRatio)
        {
            AssignFixedAspectRatio(FixedAspectRatio.x / FixedAspectRatio.y);
        }

        if (_cameraTrolleys == null)
        {
            _cameraTrolleys = FindObjectsOfType <CameraTrolley>();

            Debug.Log("Found " + _cameraTrolleys.Length + " camera trolleys.");
        }

        Transform = gameObject.transform;

        _playerController = GameManager.Instance.Player;

        // we set the target of the camera to our player through code
        Target = _playerController.transform;

        _lastTargetPosition = Target.transform.position;

        _targetedTransformPositionX = _lastTargetPosition.x;

        _characterPhysicsManager = Target.GetComponent <CharacterPhysicsManager>();

        Logger.Info("Window size: " + Screen.width + " x " + Screen.height);
    }
    public override void Dispose()
    {
        PlayerController.PlayerState &= ~PlayerState.ClimbingLadderTop;
        PlayerController.PlayerState &= ~PlayerState.ClimbingLadder;

        CharacterPhysicsManager.WarpToGrounded();
    }
    private bool PlayerHasEnoughVerticalSpaceToGetUp()
    {
        var currentHeightToStandUprightHeightDelta =
            PlayerController.StandIdleEnvironmentBoxColliderSize.y - PlayerController.EnvironmentBoxCollider.size.y;

        return(CharacterPhysicsManager.CanMoveVertically(currentHeightToStandUprightHeightDelta));
    }
Exemplo n.º 4
0
    protected override ControlHandlerAfterUpdateStatus DoUpdate()
    {
        _velocity.y += _gravity * Time.deltaTime;

        CharacterPhysicsManager.Move(_velocity * Time.deltaTime);

        return(_controlHandlerUpdateStatus);
    }
Exemplo n.º 5
0
    void Awake()
    {
        CharacterPhysicsManager = GetComponent <CharacterPhysicsManager>();

        CharacterPhysicsManager.BoxCollider = GetComponent <BoxCollider2D>();
        CharacterPhysicsManager.PrimeRaycastOrigins();
        CharacterPhysicsManager.RecalculateDistanceBetweenRays();
    }
Exemplo n.º 6
0
    public BaseControlHandler(CharacterPhysicsManager characterPhysicsManager, float duration)
    {
        GameManager = GameManager.Instance;

        CharacterPhysicsManager = characterPhysicsManager;

        Duration = duration;

        ResetOverrideEndTime();
    }
Exemplo n.º 7
0
    protected virtual bool CanJump()
    {
        if (!CharacterPhysicsManager.CanMoveVertically(
                VERTICAL_COLLISION_FUDGE_FACTOR,
                (PlayerController.PlayerState & PlayerState.Crouching) == 0))
        {
            // if we crouch we don't allow edge slide up to simplify things
            return(false);
        }

        return(PlayerController.IsGrounded() ||
               Time.time - PlayerController.CharacterPhysicsManager.LastMoveCalculationResult.CollisionState.LastTimeGrounded < PlayerController.JumpSettings.AllowJumpAfterGroundLostThreashold);
    }
Exemplo n.º 8
0
    public void Respawn()
    {
        transform.parent = null; // just in case we were still attached

        AdjustedGravity = JumpSettings.Gravity;

        CharacterPhysicsManager.Reset(SpawnLocation);

        ResetControlHandlers(new DefaultPlayerControlHandler(this));

        _gameManager.RefreshScene(SpawnLocation);

        PlayerHealth.Reset();
    }
Exemplo n.º 9
0
    public BallisticTrajectoryControlHandler(CharacterPhysicsManager characterPhysicsManager, Vector3 startPosition, Vector3 endPosition, float gravity
                                             , float angle)
        : base(characterPhysicsManager)
    {
        base.doDrawDebugBoundingBox = true;
        base.debugBoundingBoxColor  = Color.cyan;

        if (characterPhysicsManager != null)
        {
            characterPhysicsManager.onControllerBecameGrounded += (GameObject obj) =>
            {
                _keepAlive = false;
            };
        }

        _gravity  = gravity;
        _velocity = DynamicsUtility.GetBallisticVelocity(endPosition, startPosition, angle, _gravity);

        Logger.Trace("Ballistic start velocity: " + _velocity + ", (startPosition: " + startPosition + ", endPosition: " + endPosition + ", gravity: " + gravity + ", angle: " + angle + ")");
    }
Exemplo n.º 10
0
    public BallisticTrajectoryControlHandler(
        CharacterPhysicsManager characterPhysicsManager,
        Vector3 startPosition,
        Vector3 endPosition,
        float gravity,
        float angle)
        : base(characterPhysicsManager)
    {
        SetDebugDraw(Color.cyan, true);

        if (characterPhysicsManager != null)
        {
            characterPhysicsManager.ControllerBecameGrounded +=
                _ => _controlHandlerUpdateStatus              = ControlHandlerAfterUpdateStatus.CanBeDisposed;
        }

        _gravity = gravity;

        _velocity = DynamicsUtility.GetBallisticVelocity(endPosition, startPosition, angle, _gravity);

        Logger.Trace("Ballistic start velocity: " + _velocity + ", (startPosition: " + startPosition + ", endPosition: " + endPosition + ", gravity: " + gravity + ", angle: " + angle + ")");
    }
Exemplo n.º 11
0
 public BaseControlHandler(CharacterPhysicsManager characterPhysicsManager)
     : this(characterPhysicsManager, -1)
 {
 }
Exemplo n.º 12
0
    protected void MoveHorizontally(
        ref float moveDirectionFactor,
        float speed,
        float gravity,
        PlatformEdgeMoveMode platformEdgeMoveMode,
        float edgeTurnAroundPause = 0f,
        float?jumpVelocityY       = null)
    {
        var velocity = CharacterPhysicsManager.Velocity;

        if (_pauseAtEdgeEndTime.HasValue)
        {
            if (_pauseAtEdgeEndTime.Value > Time.time)
            {
                velocity.x = 0f;

                if (jumpVelocityY.HasValue)
                {
                    velocity.y = jumpVelocityY.Value;
                }

                velocity.y += gravity * Time.deltaTime;

                CharacterPhysicsManager.Move(velocity * Time.deltaTime);

                return;
            }
            else
            {
                // would go over edge, so change direction
                moveDirectionFactor *= -1;

                _pauseAtEdgeEndTime = null;
            }
        }

        // move with constant speed
        velocity.x = moveDirectionFactor * speed;

        if (jumpVelocityY.HasValue)
        {
            velocity.y = jumpVelocityY.Value;
        }
        else if (CharacterPhysicsManager.LastMoveCalculationResult.CollisionState.Below)
        {
            velocity.y = 0;
        }

        // apply gravity before moving
        velocity.y += gravity * Time.deltaTime;

        var moveCalculationResult = CharacterPhysicsManager.CalculateMove(velocity * Time.deltaTime);

        switch (platformEdgeMoveMode)
        {
        case PlatformEdgeMoveMode.TurnAround:

            var isOnEdge = (moveCalculationResult.CollisionState.WasGroundedLastFrame && moveCalculationResult.CollisionState.Below && !moveCalculationResult.CollisionState.IsFullyGrounded); // we are on edge

            if (
                isOnEdge ||
                (moveDirectionFactor < 0f && moveCalculationResult.CollisionState.Left) ||
                (moveDirectionFactor > 0f && moveCalculationResult.CollisionState.Right)
                )
            {
                if (isOnEdge && edgeTurnAroundPause > 0f)
                {
                    velocity.x = 0f;

                    CharacterPhysicsManager.Move(velocity * Time.deltaTime);

                    _pauseAtEdgeEndTime = Time.time + edgeTurnAroundPause;
                }
                else
                {
                    // would go over edge, so change direction
                    moveDirectionFactor *= -1;

                    velocity.x = moveDirectionFactor * speed;

                    CharacterPhysicsManager.Move(velocity * Time.deltaTime);
                }
            }
            else
            {
                CharacterPhysicsManager.PerformMove(moveCalculationResult);
            }
            break;

        case PlatformEdgeMoveMode.FallOff:

            if (
                (moveDirectionFactor < 0f && moveCalculationResult.CollisionState.Left) ||
                (moveDirectionFactor > 0f && moveCalculationResult.CollisionState.Right)
                )
            {
                // would go over edge, so change direction
                moveDirectionFactor *= -1;

                velocity.x = moveDirectionFactor * speed;

                CharacterPhysicsManager.Move(velocity * Time.deltaTime);
            }
            else
            {
                CharacterPhysicsManager.PerformMove(moveCalculationResult);
            }

            break;
        }
    }
Exemplo n.º 13
0
    private bool IsCloseToFloor()
    {
        CharacterPhysicsManager.PrimeRaycastOrigins();

        return(CharacterPhysicsManager.IsFloorWithinDistance(.1f));
    }