Turn Toward Normal Direction

I’d like to know how I can have an object rotate in the direction of the normal of a face that it has just cast a ray toward.

My problem is illustrated below, in steps:

A. The player (green triangle) cast a ray forward and it hits a face on a wall.

B. The direction in which that normal “points” is noted.

C. The player rotates toward that direction, in this case right.

Obstacle avoidance, eh? :wink:

The best way to do it is probably to use yourTransform.InverseTransformDirection(normalVector). You can then check the .x value of the resulting vector of that - turn left if it’s negative, right if it’s positive.

How’d you know? :wink:

Okay, StarManta, you aren’t getting off that easy. :wink:

I’m using the code below, which is my lame interpretation of your suggestion, but it doesn’t seem to be doing what it should. Am I missing something?

if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit, watchDistance)) {
		
			checkVector = transform.InverseTransformDirection(hit.normal);
			
			if (checkVector.x > 0) {
			
				transform.Rotate(0, Time.deltaTime, 0);
				
			} else {
			
				transform.Rotate(0, -Time.deltaTime, 0);
			}
				
		}