How can I calculate new direction angle when player hits wall diagonally?

I want to make snake to bounce off of wall, I need only to change direction. For example, if it hit left wall at 45deg going up it needs to rotate to the right for 90deg, and continue going up and right at 45deg angle (relative to wall). This must work for arbitrary wall angle.

Like this (+ is head, * is hit point, ! is wall, / is snake):

    ! /
    ! \

I’m moving snake head with translate forward, and make other parts follow it.

I’m trying to make it work by calculating reflect vector, but I don’t know how to rotate head in it’s direction.

Screenshot of progress so far:

You need the normal of the wall. A normal points out from the surface:


How you get the normal will depend on how to built your game and how you are detecting your collisions.

Given the normal, you can use Vector3.Reflect() to calculate the new direction.