I’m hoping that I’m just overlooking something silly, but i just cant seem to figure out where I’m going wrong here. Basically I am trying to push a Rigidbody cube with a CharacterController. I have a player object with a character controller, all of the movement is done using the Move action through script, and i have a seperate script attached to the same object that simply handles pushing objects :
public class PushRigidbodies : MonoBehaviour
{
[Header("Basics")]
public LayerMask pushLayers = new LayerMask();
[Range(0.5f, 5f)] public float strength = 1.1f;
public void Reset()
{
pushLayers = LayerMask.GetMask("Default");
}
public void PushRigidBodies(ControllerColliderHit hit)
{
Debug.Log("Collision Detected!");
var body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic) return;
var bodyLayerMask = 1 << body.gameObject.layer;
if ((bodyLayerMask & pushLayers.value) == 0) return;
if (hit.moveDirection.y < -0.3f) return;
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0.0f, hit.moveDirection.z);
body.AddForce(pushDir * strength, ForceMode.Impulse);
}
}
However, the debug log is never called when running into objects on the specified layer and they behave as impassable walls… The cubes I am trying to push have both a box collider (not set to trigger) & a Rigidbody component (Using gravity, not kenematic), and they can be pushed and moved by other Rigidbodies just fine. I hope all of that makes sense and if I left out any important details please let me know, thanks!!