What is the trick for making the FPS controller be able to “push” a crate? I already can make it stop with collider “walls” – i want to be able to “bulldoze” crates and stuff.
Use this code. It is from the documentation. ![]()
// 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;
}
If you don’t mind (Like I said: I’m green): This script is attached to the FPS controller, right? Also where in the Docs does your example come from.
Thanks
Dave
answered my own question-- yes its attached to controller thanx again