protected override bool DoUpdate() { CheckOneWayPlatformFallThrough(); Vector3 velocity = _playerController.characterPhysicsManager.velocity; float yVelocity = Mathf.Max( GetGravityAdjustedVerticalVelocity(velocity, _playerController.adjustedGravity, true) , _playerController.jumpSettings.maxDownwardSpeed); MoveCalculationResult moveCalculationResult = _playerController.characterPhysicsManager.SlideDown(_platformDirection, yVelocity * Time.deltaTime); if (_platformDirection == Direction.Left && !moveCalculationResult.collisionState.left) { return(false); } if (_platformDirection == Direction.Right && !moveCalculationResult.collisionState.right) { return(false); } Logger.Trace("PlayerMetricsDebug", "Position: " + _playerController.transform.position + ", Velocity: " + velocity); return(true); }
protected void MoveHorizontally(ref float moveDirectionFactor, float speed, float gravity, PlatformEdgeMoveMode platformEdgeMoveMode, float edgeTurnAroundPause = 0f , float?jumpVelocityY = null) { Vector3 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; MoveCalculationResult moveCalculationResult = _characterPhysicsManager.CalculateMove(velocity * Time.deltaTime); switch (platformEdgeMoveMode) { case PlatformEdgeMoveMode.TurnAround: bool 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; } }