コード例 #1
0

        
コード例 #2
0
        private void UpdateCharacterState(LOCOMOTION_SYSTEM locomotionSystem)
        {
            Vector3 worldVelocity = Vector3.zero;
            bool    isSliding     = this.currentLocomotionSystem.isSliding;
            bool    isGrounded    = true;

            switch (locomotionSystem)
            {
            case LOCOMOTION_SYSTEM.CharacterController:
                worldVelocity = this.characterController.velocity;
                isGrounded    = (
                    this.characterController.isGrounded ||
                    Time.time - this.lastGroundTime < GROUND_TIME_OFFSET
                    );
                break;

            case LOCOMOTION_SYSTEM.NavigationMeshAgent:
                worldVelocity = (this.navmeshAgent.velocity == Vector3.zero
                        ? this.characterController.velocity
                        : this.navmeshAgent.velocity
                                 );
                isGrounded = (
                    !this.navmeshAgent.isOnOffMeshLink ||
                    Time.time - this.lastGroundTime < GROUND_TIME_OFFSET
                    );
                break;
            }

            Vector3 localVelocity = this.character.transform.InverseTransformDirection(worldVelocity);

            this.character.characterState.forwardSpeed  = localVelocity;
            this.character.characterState.sidesSpeed    = Mathf.Atan2(localVelocity.x, localVelocity.z);
            this.character.characterState.verticalSpeed = worldVelocity.y;

            this.character.characterState.pivotSpeed = this.currentLocomotionSystem.pivotSpeed;

            this.character.characterState.isGrounded = isGrounded ? 1f : 0f;
            this.character.characterState.isSliding  = isSliding ? 1f : 0f;
            this.character.characterState.isDashing  = this.currentLocomotionSystem.isDashing ? 1f : 0f;
            this.character.characterState.normal     = this.terrainNormal;
        }
コード例 #3
0

        
コード例 #4
0
        private void UpdateCharacterState(LOCOMOTION_SYSTEM locomotionSystem)
        {
            bool isRising = IsRisingOrFalling() && (VectorMath.GetDotProduct(this.momentum, this.locomotionDriver.transform.up) > 0f);

            switch (this.character.characterState.locomotionState)
            {
            case Character.LocomotionState.Grounded:
                if (isRising)
                {
                    this.character.characterState.locomotionState = Character.LocomotionState.Rising;
                    break;
                }
                if (!this.locomotionDriver.IsGrounded())
                {
                    this.character.characterState.locomotionState = Character.LocomotionState.Falling;
                    OnGroundContactLost();
                    break;
                }
                break;

            case Character.LocomotionState.Falling:
                if (isRising)
                {
                    this.character.characterState.locomotionState = Character.LocomotionState.Rising;
                    break;
                }
                if (this.locomotionDriver.IsGrounded())
                {
                    this.character.characterState.locomotionState = Character.LocomotionState.Grounded;
                    OnGroundContactRegained(momentum);
                    break;
                }
                break;

            case Character.LocomotionState.Rising:
                if (!isRising)
                {
                    if (this.locomotionDriver.IsGrounded())
                    {
                        this.character.characterState.locomotionState = Character.LocomotionState.Grounded;
                        OnGroundContactRegained(momentum);
                    }
                    else
                    {
                        this.character.characterState.locomotionState = Character.LocomotionState.Falling;
                    }
                }
                break;

            default:
                this.character.characterState.locomotionState = Character.LocomotionState.Falling;
                break;
            }

            // TODO cleanup
            Vector3 worldVelocity = Vector3.zero;
            bool    isSliding     = this.currentLocomotionSystem.isSliding;
            bool    isGrounded    = true;

            switch (locomotionSystem)
            {
            case LOCOMOTION_SYSTEM.LocomotionDriver:
                worldVelocity = this.locomotionDriver.GetVelocity();
                isGrounded    = (
                    this.locomotionDriver.IsGrounded() ||
                    Time.time - this.lastGroundTime < GROUND_TIME_OFFSET
                    );
                break;

            case LOCOMOTION_SYSTEM.NavigationMeshAgent:
                worldVelocity = (this.navmeshAgent.velocity == Vector3.zero
                        ? this.locomotionDriver.GetVelocity()
                        : this.navmeshAgent.velocity
                                 );
                isGrounded = (
                    !this.navmeshAgent.isOnOffMeshLink ||
                    Time.time - this.lastGroundTime < GROUND_TIME_OFFSET
                    );
                break;
            }

            Vector3 localVelocity = this.character.transform.InverseTransformDirection(worldVelocity);

            this.character.characterState.forwardSpeed  = localVelocity;
            this.character.characterState.sidesSpeed    = Mathf.Atan2(localVelocity.x, localVelocity.z);
            this.character.characterState.verticalSpeed = worldVelocity.y;

            this.character.characterState.pivotSpeed = this.currentLocomotionSystem.pivotSpeed;

            this.character.characterState.isGrounded = isGrounded ? 1f : 0f;
            this.character.characterState.isSliding  = isSliding ? 1f : 0f;
            this.character.characterState.isDashing  = this.currentLocomotionSystem.isDashing ? 1f : 0f;
            this.character.characterState.normal     = this.terrainNormal;
        }