Ejemplo n.º 1
0
 /// <summary>
 /// Call this at the end of FixedUpdate, after you have moved the character.
 /// This ensures GroundVelocity is properly calculated on the next frame.
 /// </summary>
 public void RecordFootprintPos(Vector3 pos)
 {
     if (IsGrounded)
     {
         _lastPositionRelativeToGround = CurrentGround.InverseTransformPoint(pos);
     }
 }
Ejemplo n.º 2
0
        public void Setup(StageMaster master)
        {
            DispatchEvent <Action <UI.StageCanvas> >(StageEvents.RequestStageCanvas, c => _stageCanvas             = c);
            DispatchEvent <Action <CharacterManager> >(StageEvents.RequestCharacterManager, c => _characterManager = c);
            _stageMaster = master;

            CreateGround(master.RoundSettings, () => CurrentGround.ActivationWalls(true));

            StartStage();
        }
Ejemplo n.º 3
0
        private void OnCreateEnemy(EnemyController enemy, EnemyMaster master)
        {
            var startPos = CurrentGround.GetRandomPosition();

            enemy.transform.localPosition = startPos;
            enemy.Setup(master);
            enemy.SetTarget(Player);

            Enemies.Add(enemy);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Call this at the beginning of FixedUpdate, before you do any
    /// calculations that depend on this object's properties.
    /// </summary>
    public void UpdateGroundState(Vector3 pos)
    {
        RaycastHit?hit = GetGround(pos);

        // Update the height above the ground
        HeightAboveGround = hit.HasValue
            ? hit.Value.distance - RAYCAST_OFFSET
            : RAYCAST_DISTANCE;   // If we're over a void, then we're Really F****n' High(tm)

        // We're grounded if our height is below a threshold
        WasGroundedLastFrame = IsGrounded;
        IsGrounded           = HeightAboveGround < GROUND_DETECTOR_THICKNESS;

        // Update the current ground.
        var previousGround = CurrentGround;

        CurrentGround = IsGrounded
            ? hit.Value.transform
            : null;

        // Record the last time we were grounded
        if (IsGrounded)
        {
            LastGroundedTime = Time.time;
        }

        // Update the ground normal
        if (IsGrounded)
        {
            LastGroundNormal = hit.Value.normal;
        }

        // Calculate how fast the ground is moving (aka: the ground velocity)
        if (IsGrounded && CurrentGround == previousGround)
        {
            // Figure out where our "foot prints" have moved to
            var currentFootprintsPos = CurrentGround.TransformPoint(_lastPositionRelativeToGround);
            var lastFootprintsPos    = pos;

            // Figure out how much the footprints moved, and move by that much
            var deltaFootprints = currentFootprintsPos - lastFootprintsPos;
            GroundVelocity = deltaFootprints / Time.deltaTime;
        }
        else
        {
            // If we're not on a platform, then the ground velocity is zero.
            // If we're standing on a *different* platform than before, then we
            // have no way of tracking its velocity, so we'll just cheat and set
            // it to zero in that case too.
            GroundVelocity = Vector3.zero;
        }
    }
Ejemplo n.º 5
0
        private void StartRound()
        {
            _grounds.ForEach(c => c.CloseAllExit());
            _grounds.ForEach(c => c.ActivationWalls(false));
            CurrentGround.ActivationWalls(true);

            _characterManager.ClearEnemies();
            if (Player == null)
            {
                _characterManager.CreateNewPlayer(_playerParent, OnCreatePlayer);
            }

            _bornEnemyLoopCoroutine = StartCoroutine(BornEnemyLoop());

            Player.SetCanMove(true);

            _stageCanvas.RoundTimer.StartTimer(3, OnEndTimer);
        }