Hi,
May be it is quite simple question, but cant figure out how it should be done. Idea is to get angle for Y terrain normal, then get a half of this angle and apply it to GameObject rotation. GameObjects is rotated to some target as well. Here is my function:
function getTerrainRot(myTarget:Vector3,terrPos: Vector3,modelRot:Quaternion){
var terrHit: RaycastHit;
var newPos: Vector3;
var normal_q: Quaternion;
var rot: Quaternion;
if(Physics.Raycast (terrPos, -Vector3.up, terrHit, 10.0)){
normal_q = Quaternion.FromToRotation(Vector3.up, terrHit.normal);
}
normal_q = Quaternion.Lerp(modelRot,normal_q,0.5);
newPos = myTarget - terrPos;
newPos.y = 0;
rot = normal_q * Quaternion.FromToRotation(Vector3.forward, newPos);
return Quaternion.Slerp(modelRot, rot, Time.deltaTime*5);
}
But it return changes for whole XYZW rotation, but I need only for Y.
Thanks