예제 #1
0
    private void ApplyForce(IAerodynamicSurface surface)
    {
        for (int i = 0; i < _affectedBodies.Length; i++)
        {
            AffectedBody affectedBody = _affectedBodies[i];
            var          position     = _airfoil.transform.TransformPoint(_airfoil.Center);
            var          linearForce  = (_airfoil.LiftForce + _airfoil.DragForce) * affectedBody.Share;
            affectedBody.Body.AddForceAtPosition(linearForce, position);

            // Todo: Moment torque
        }
    }
    private void ApplyForce(IAerodynamicSurface surface)
    {
        for (int i = 0; i < _affectedBodies.Length; i++)
        {
            AffectedBody affectedBody = _affectedBodies[i];
            for (int j = 0; j < _airfoil.SectionStates.Length; j++)
            {
                var section  = _airfoil.SectionStates[j];
                var position = _airfoil.transform.TransformPoint(section.LocalPosition);
                var force    = (section.Lift + section.Drag) * affectedBody.Share;
                affectedBody.Body.AddForceAtPosition(force, position);

                // Todo: Moment Torque
            }
        }
    }
예제 #3
0
    private void MoveCharacter()
    {
        float horizontalForce = 0;
        float verticalForce   = 0;

        var prevAnimeState    = GetAnimeFromState(prevState);
        var currentAnimeState = GetAnimeFromState(currentState);
        var isFacingRight     = IsFacingRight(currentState);

        float horizontalVelocity = 0;

        if (currentAnimeState == AnimeState.Idle || currentAnimeState == AnimeState.Run || currentAnimeState == AnimeState.SideClimb || currentAnimeState == AnimeState.SideClimbIdle || currentAnimeState == AnimeState.TopClimb || currentAnimeState == AnimeState.TopClimbIdle || currentState == SpecificState.FallMoveLeft || currentState == SpecificState.FallMoveRight || currentState == SpecificState.JumpMoveLeft || currentState == SpecificState.JumpMoveRight)
        {
            if (currentAnimeState == AnimeState.TopClimb)
            {
                horizontalVelocity = (isFacingRight ? 1 : -1) * climbSpeed;
            }
            else if (currentAnimeState != AnimeState.Idle && currentAnimeState != AnimeState.TopClimbIdle && currentAnimeState != AnimeState.SideClimb && currentAnimeState != AnimeState.SideClimbIdle)
            {
                horizontalVelocity = (isFacingRight ? 1 : -1) * speed;
            }
        }
        horizontalForce = PhysicsHelpers.CalculateRequiredForceForSpeed(AffectedBody.mass, AffectedBody.velocity.x, horizontalVelocity, Time.fixedDeltaTime);

        if (currentAnimeState == AnimeState.SideClimb || currentAnimeState == AnimeState.SideClimbIdle || currentAnimeState == AnimeState.TopClimb || currentAnimeState == AnimeState.TopClimbIdle || (currentAnimeState == AnimeState.Jump && prevAnimeState != AnimeState.Jump))
        {
            float verticalSpeed = 0;
            if (currentState == SpecificState.ClimbRightUp || currentState == SpecificState.ClimbLeftUp)
            {
                verticalSpeed = climbSpeed;
            }
            else if (currentState == SpecificState.ClimbLeftDown || currentState == SpecificState.ClimbRightDown)
            {
                verticalSpeed = -climbSpeed;
            }
            else if (currentAnimeState != AnimeState.SideClimbIdle && currentAnimeState != AnimeState.TopClimb && currentAnimeState != AnimeState.TopClimbIdle)
            {
                verticalSpeed = jumpSpeed;
            }

            verticalForce = PhysicsHelpers.CalculateRequiredForceForSpeed(AffectedBody.mass, AffectedBody.velocity.y, verticalSpeed, Time.fixedDeltaTime, true);
        }

        AffectedBody.AddForce(Vector2.right * horizontalForce + Vector2.up * verticalForce);
    }