# Detect facing normal of trigger mesh?

I am making a top-down puzzle game, similar to the old Chip’s Challenge… if anyone played that… I want to implement an ice-floor like in pokemon:

I have a problem, I have 360 degree movement, so detecting which direction i have approached the ice from can not be done by simply detecting button input. NOR can it be done by detecting the player’s facing direction.

The reason is:

• Pretend you are heading North-East, you approach an ice floor.
• You COULD step on to the ice from the south, orrrrr you could step on to it from the west. Both could be achieved with a 45 degree facing angle, and pressing UP or RIGHT buttons will not tell us whether the player should slide north or east.
• Notice that in Pokemon, the player can only slide in one of four directions, even though when you are not on the ice, you can go in 360.

Character controller and state machine are easy, I am stuck on figuring out which way I should slide.

If you’re building your terrain with blocks, you could give those blocks an “Ice” tag. Then, in your player control script, fire a quick raycast down to see if the ground is ice. If it is, and depending on which direction the player moves in, use rigidbody.constraints (Unity - Scripting API: RigidbodyConstraints) to lock the movements to specific axis.

If you place triggers on those ice tiles with their trasforms in the middle of tile, you can determine which way to slide this way:

1. Once player enters trigger, you make a vector starting in players position and ending in center of tile. (trigger.transform.position - player.transform.position)
2. Then you compare modules of x and y of this vector and choose the greatest one. If the greatest is |x| - ok, you slide horizontally, left if x < 0, right if x > 0. If |y| is greater, slide vertically, y< 0 means down, y > 0 - means up.