Unity3d How to make an GameObject be affected by other GameObject movements

let’s just say i have a ball and a plane cube being rotated on loop, when this ball gets into this rotating cube, it should be pushed away when it collides depending on the position and rotation’s speed.

I’m just a newbie on unity and i’m starting to make scripts on javascript (i’ll do C# when i get enough knowledge), i made research on google about gameobjects being pushed by other objects… i thought this script has to be in the affected object:

#pragma strict

var pushPower = 2.0;

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

    if(body == null || body.isKinematic)
        return;

    if(hit.moveDirection.y < 1.3)
        return;

    var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

    body.velocity = pushDir * pushPower;
}

but it seems not to work, the ball just goes through the plane cube and then it falls, how can i get it being affected by this kind of physics?

You don’t need any scripting to achieve a rather good effect. Just let the Rigidbodies do their work.

  1. Have a rotating cube that has both a collider and a rigidbody on it.
  2. Have a sphere that has both a collider and rigidbody on it.
  3. Ensure neither GameObject’s rigidbodies are set to isKinematic.
  4. Drop the sphere onto or in the path of the rotating cube.

The sphere will be pushed as intuitively expect.