Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Pushing a box

Discussion in 'Editor & General Support' started by Littlenorwegians, Dec 27, 2011.

  1. Littlenorwegians

    Littlenorwegians

    Joined:
    Dec 14, 2011
    Posts:
    41
    Right, where would we be if we didn't push boxes in this medium?

    Anyways, this is quite easy. I am using the first person controller and I want it to be able to move a box with rigidbody physics. Now, how do I do that?
     
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    1. Add rigidbody and box collider to box.
    2. Make animation to what you want to move the box for the character
    3. Make animation play when moving box or pressing a button to play the animation.
    Done. :)
     
  3. Steffan-Poulsen

    Steffan-Poulsen

    Joined:
    Dec 27, 2011
    Posts:
    123
    Another solution could be to add a script to your character controller along the lines of this:

    function OnCollisionStay(other : Collision) {

    if (other.rigidbody != null) {
    other.rigidbody.WakeUp();
    }

    }
     
  4. windexglow

    windexglow

    Joined:
    Jun 18, 2010
    Posts:
    378
    You can also use rigidbody.AddRelativeForce(vector3) to move the player. Mass is kind of acceleration, drag is kind of max speed.
     
  5. TehWut

    TehWut

    Joined:
    Jun 18, 2011
    Posts:
    1,577
    for character controller and rigidbodies you will need to use OnControllerColliderHit
     
  6. Littlenorwegians

    Littlenorwegians

    Joined:
    Dec 14, 2011
    Posts:
    41
    Woah, this is heavy to me. (A bit new to scripts. Currently using uScript)

    Tried what Steffan said, but with no success.
    (Added the script to the CharacterMotor script)
     
  7. Steffan-Poulsen

    Steffan-Poulsen

    Joined:
    Dec 27, 2011
    Posts:
    123
    Does your character controller have a rigidbody, as well as your "box"?
     
  8. Littlenorwegians

    Littlenorwegians

    Joined:
    Dec 14, 2011
    Posts:
    41
    Well, I can easily add it. Why?
     
  9. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Because all moving objects need Rigidbodies to move. :)