I tried multiple ways of clamping a physics based rigidbody to the z axis of 0, but they all look awkward and mess up interaction between the rigidbody and other. Does anyone have experience with this and can give me a nice way of doing it? 
Cookie for answer!
Did you try something like this?
enum Axes{x, y, z, none};
var fixedAxis: Axes;
var initialPosition: Vector3;
function Awake()
{
initialPosition = transform.position;
}
function LateUpdate()
{
switch(fixedAxis)
{
case Axes.x: transform.position.x = initialPosition.x;
break;
case Axes.y: transform.position.y = initialPosition.y;
break;
case Axes.z: transform.position.z = initialPosition.z;
}
}
Works fine for me.
A simple rigidbody.velocity.z = 0; and transform.position.z = 0; would do it.
The way I would recommend doing this is to add a configurable joint to the rigidbody and set the ZMotion value to Locked.
First of all, thanks for making me notice the LateUpdate(), makes a lot much easier
This worked for me:
void LateUpdate(){
rigidbody.velocity = new Vector3(rigidbody.velocity.x,rigidbody.velocity.y,0f);
transform.position = new Vector3(transform.position.x,transform.position.y,0f);
}
When I attach the configurable joint to the player, the rigidbodies behavious becomes very strange, it shoots back to its original position in stange ways. Any ideas why? because it does sound like a decent solution, although already solved 
Generally, you shouldn’t attempt to set transform.position for an object which is controlled by physics. This is particularly true when you are using a joint, as the joint can get “confused” quite easily. Also, make sure none of the configurable joint’s spring parameters are enabled (the joint limits should be set to Locked rather than Limited). Also also, make sure the joint’s Configured In World Space flag is set unless you need the joint’s direction to change with the object’s rotation.