title: Pulling / Pushing a 3D unity object using physics
body: <p>I'm making a 3D puzzle platformer game with two characters. You can switch back and forth between characters using an Input. I'm using physics to control my characters . I want my only one character to be able to push and pull blocks, and on one axis at a time (X or Z-axis). For the puzzle i'm designing, I also want the other character to stand on the block to move him to a higher ledge, but i cannot do that unless the object is kinematic. (which means the ground check isn't satisfied when the character is standing on a rigidbody)</p>
  
  <p>It's also worth nothing that I made it so that the character that jumps on the block becomes a child of the object so it moves with the object. </p>
  
  <p>What should I do?</p>
  
  <p>I tried using the below code from the Unity API on Rigidbodies attached to the player, but still no luck.</p>
  
  <p>Also supplying the ground check of my physics controller.</p>
  
  <pre><code>public float pushPower = 2.0f;
  
   void OnCollisionEnter(Collision hit)
   {
       Rigidbody body = hit.collider.attachedRigidbody;
       // no rigidbody
       if (body == null || body.isKinematic)
           return;
       // We dont want to push objects below us
       if (hit.transform.position.y &lt; -0.3f)
           return;
       // Calculate push direction from move direction,
       // we only push objects to the sides never up and down
       Vector3 pushDir = new Vector3(hit.transform.position.x, 0, hit.transform.position.z);
       // If you know how fast your character is trying to move,
       // then you can also multiply the push velocity by that.
       // Apply the push
       body.velocity = pushDir * pushPower;
   }
  
          public virtual void Jump()
          {
              // conditions to do this action
              bool jumpConditions = isGrounded &amp;&amp; !isJumping;
              // return if jumpCondigions is false
              if (!jumpConditions) return;
              // trigger jump behaviour
              jumpCounter = jumpTimer;            
              isJumping = true;
              // trigger jump animations            
              if (_rigidbody.velocity.magnitude &lt; 1)
                  animator.CrossFadeInFixedTime("Jump", 0.1f);
              else
                  animator.CrossFadeInFixedTime("JumpMove", 0.2f);
          }
  </code></pre>
  
  <p>Right now using the code, the object slides away as soon as the character collides with it. </p>