I want an enemy to walk on walls and any angle. I´m using a raycast with this code so enemy rotates with normal. The problem is with big angles when enemy is near to 90º. Then it goues crazy and runs trought the plane. I add and image to explain what i want to tod. The code i use is:
if(Physics.Raycast(thisTransform.position,thisTransform.up * -1f,out Hit,10f))
{
thisTransform.position = new Vector3(thisTransform.position.x - 1f * Time.deltaTime,Hit.point.y + 4.5f,thisTransform.position.z);
thisTransform.localRotation = Quaternion.FromToRotation (Vector3.up, Hit.normal);
}
EDIT: Rotation works well, the problem is to try to keep the enemy at some distance of the plane so it always is on the plane and not under.
Thanks!

I think the problem is with this line:-
thisTransform.position = new Vector3(thisTransform.position.x - 1f * Time.deltaTime,Hit.point.y + 4.5f,thisTransform.position.z);
You are adding an offset in a world space direction to the hit point to get the new position. I’m not sure exactly how the object is moving but I think you want something like this:-
var castPos = thisTransform.position + thisTransform.right * Time.deltaTime;
if(Physics.Raycast(castPos, thisTransform.up * -1f,out Hit,10f))
{
thisTransform.position = hit.point + hit.normal * 4.5;
thisTransform.localRotation = Quaternion.FromToRotation (Vector3.up, Hit.normal);
}
Basically, cast the ray a little way ahead of the object, then get the normal at that point and use it to position and rotate the transform.
Oh! It works!! Really thanks. Yoy save days of works. Really really thanks 