what do i have to do, to make get the Y of the character stay at the red wall, while still being able to move left and right/up down?
Also note, that the red and white boxes are just there for showing the problem. Only the blue box will be there in the end - without a collider. So raycasting down to the red cube wont be possible
so i figured out if i use a raycast down from the character (-transform.up) it does exactly what i want.
but the red and white box wont be there in the game, there is nothing to raycast against. all i know is the position of the blue cube. i just wonder how i can do it all without the raycast?
but in the end, there wont be a collider on the cubes at all - i think its better to think of the blue cube as an empty gameobject - so sadly, a raycst wont work
So if you are dealing with a single point in space.
Then your objects position is clamped to that point, +- Bounds.x and Bounds.y. If object can’t exceed the point in space +- bounds x and bounds y, then it will remain in the parameters of those bounds but will be moveable within.
the bounds x and bounds y may technically be point parent or empty object +/- transform right * boundsX and +- transform up * boundsY.
Or If there is no transform then you will need to get the facing of point in space where the mathematical plane will be oriented. Which will need to be obtained by referencing a global vector direction.