Hi there,
I’d like to thank anyone in advance for helping me out on this issue.
I’ve got a game object that is constantly raycasting in front of it. I’m trying to get a direction vector pointing upwards from the raycast hit point (orthogonal to the hit.normal but upwards in relation to the player object’s upward orientation.)

All I can use to get this direction vector is the raycast hit normal and player transform directions. I cannot use the rotations of the surfaces

I’ve looked into various quaternion methods as I use them in other parts of my project. I need the forward vector parameter for:

Quaternion target = Quaternion.LookRotation(Vector3 forward, Vector3 up);

I’ve attached a diagram to better illustration my issue.

n.b The Orientation of the “Wall” is irrelevant, as the direction vector I’m looking for will always be 90 degrees from the normal. This functionality needs to be applicable to all rotations of “Wall” the raycast will hit.

I appreciate any help you can give :slight_smile:

Hopefully the third time is the charm. I answered twice, and deleted the answer twice as my approaches had issues. The code is untested, but at least conceptually I think I got it right this time. The code projects Vector3.up on the plane defined by the normal. It checks for the special case of the hit plane being perfectly flat, or if Vector3.zero is passed as a parameter.

This uses the world up. If you need the up of the character, add a second parameter and use that parameter in place of Vector3.up in the code:

function FindUp(normal : Vector3) : Vector3 {
	normal.Normalize();
	if (normal == Vector3.zero)
		return Vector3.up;
	if (normal == Vector3.up) 
		return Vector3.forward;
		
	var distance = -Vector3.Dot(normal, Vector3.up);	
	return (Vector3.up + normal * distance).normalized;
}