コード例 #1
0
        /// <summary>
        /// Movement is handle by the ThirdPersonCharacter script from the standard Assest
        /// This is all additional Functionality I want my player to perform
        /// </summary>
        void CheckWallStatus()
        {
            //Stop force when colliding with a wall.
            float speed = 0.5f;
            //grab the input of player and find speed in X direction.
            float xMove = Input.GetAxis("Horizontal");

            if (xMove != 0)
            {
                float   xSpeed        = Mathf.Abs(xMove * player_RigidBody.velocity.x);
                Vector3 movementForce = Vector3.right;
                movementForce *= xMove * speed;
                //get playerSpeed and the maxSpeed
                if (xSpeed < 3.0f)
                {
                    RaycastHit hit;
                    if (!player_RigidBody.SweepTest(tpControl.getMove(), out hit, 0.05f))
                    {
                        player_RigidBody.AddForce(movementForce);
                    }
                }
            }
            // The logic from blueprint is that if there isn't a hit then move.
            // TPC already moves.. so reverse logic on hit stop movement... but what is stop?
            //Inspect tpControl more to determine.
        }