Constrain a Rigidbody on its axes

Hi,

I want to constrain a Rigidbody on its own axes, for example: The object should only be able to move in its forward direction.
The constraints of the Rigidbody component are only constraining in world space, so if the object is placed with an angle this does not work…

I tried to implement a script that does this, but I have no idea how to do this…

I’m greatful for hints and tips how to do this.

I found this: https://answers.unity.com/questions/1220999/rigidbody-local-position-constraints.html
Have you tried it?

Yes, I tried that. But if I freeze x and y the movement of the object is still along the worlds z-axis…

Found a solution:

I created an empty GameObject and rotated it like i need it. Then I put my object, which I want to move as a child under this new created GameObject. Then it works without any issues.

Thanks for the quick help.

1 Like