Newbie: How to "push" a cube using mode FPS

Hello, first of all im really really new…

I download the 2DGamePlayTutorial and im notice that the “boxes” or crates can be pushed if the characters collision with them.

Now i make my own “game” or just im using a FPScontroller, i create a cube with collider and rigidbody, but when i collision with the cube does not move is like solid and attached to the ground (my ground or floor is another cube). I want to walk and when i collision the cube, this can be pushed and fall…

I try to import the crate from the 2DGamePlayTutorial and it does not work

Any suggest?? thanks in advance


I did it myself:

1.- Create a Javascript file on Project window i called “Push.js”
2.- COpy the code from script documentation, this is the script:

// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;

function OnControllerColliderHit (hit : ControllerColliderHit)
    var body : Rigidbody = hit.collider.attachedRigidbody;

    // no rigidbody
    if (body == null || body.isKinematic) { return; }

    // We dont want to push objects below us
    if (hit.moveDirection.y < -0.3) { return; }

    // Calculate push direction from move direction,
    // we only push objects to the sides never up and down
    var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.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;

3.- I drag the file into “First Person Controller” on “Hierarchy window”

And thats it, i can push all objects with Rigidbody :slight_smile:

Over here.