I have a script in which when the player is touching a certain box collider the player’s x axis position and y axis rotation is aligned with the box; similar to if an imaginary line (white dashed line above) were drawn down the centre of the box from end to end, along which the player would travel and be aligned to (blue player above). This worked perfectly until I rotated the box (orange player above) and noticed that this threw the player’s alignment. What I need is to have the player align with the box along the player’s x axis and face the opposite end no matter which way the box is rotated along the box’s y axis (as in the yellow player below).
I’ve considered adding points at either ends of the boxes and therefore if the player is facing one end using the end point for the alignment, rather than always using the centre of the box for the alignment. I’m not too sure how to implement this though and whether there’s a better way altogether. How could I do this?