How can I lock the local axis of a Rigidbody?

I’m trying to make a script letting one gameobject move into another, like a nail in a plank. I have all of that working but my issue is that things can push the “nail” sideways after it’s already partially in the “plank.” Of course, that’s not how these things work so I need to prevent it. I’d much rather avoid using hard teleportation with transform.position because I’d like to keep my projects physics based, so I’d rather prevent it from moving in the first place rather than moving it back before the render updates.


The struggles comes from the fact that Unity’s Rigidbody constraints are meant for the global axis only, but if and when the rotation of it is set to, say (45, 45, 45), then I can’t lock any of the position constraints but I still need it to only be able to move along the transform.forward axis.


Knowing me I’ll probably come up with a solution later tonight after posting this question, so have a look and see if I’ve embarrassed myself or if I actually can’t figure it out.

Yeah I called it…

If anyone sees this and needs to know, I found it here…