- Home /
Facing a Wall Surface (Perpendicular)
Currently I have a character climbing a wall, which is great but if the player happens to be facing the wall at an angle, then my character will clip with the wall and "climb" it in a way that is not realistic.
To fix this, I'd like to take the normal from my RaycastHit result and use that to find the surface, then make my character rotate to face the surface square on (i.e. Zaxis is perpendicular to the surface, or alternately the Xaxis is parallel).
What is the best means of doing this?
The current information I have available include the collider of the character and the RaycastHit result from a Physics.Raycast operation.
Answer by sneftel · May 02, 2011 at 07:49 PM
You can use Quaternion.LookRotation()
for this... something like
transform.rotation = Quaternion.LookRotation(-raycastHit.normal);
That'll take care of non-vertical walls with the character right-side-up (that is, their local Z axis will point towards the surface, and their local Y axis will point as "up" as possible). If you want the character to be not right-side-up, a slightly different approach will work... let me know.
Your answer
Follow this Question
Related Questions
Finding Face Angle 0 Answers
A object and another object has keep perpendicular. 1 Answer
World Coordinates of face on a mesh 1 Answer
Viewing a transparent cutout at a distance 1 Answer
Gore System: Boolean or Culling face and redrawing? 0 Answers