Hello . I am trying to get my NPC to follow the shape of the surface he is walking on as it travels towards its target (for example: lean forward when it goes down the hill. I do raycasting to read normals of the surface, but when I try to implement that data in he will not rotate on Y axis anymore ( NPC not looking on its target anymore). It will respond to the curvature of the surface but won’t rotate as he turns. So I know how to do both separately but I can’t manage to get it to work together. It is a mobile game so it has to be very simple. Any help with the code would be deeply appreciated, even if someone knows a simple asset that I could purchase to solve that problem! Thanks a lot.
Here is the code for grabbing surface normals:
`
downward = transform.TransformDirection(Vector3.down) * 1;
Debug.DrawRay(transform.position, downward, Color.green);
if (Physics.Raycast(transform.position,(downward), out hit, 1, mask))
{
distance = hit.distance;
sheepBody.transform.position = hit.point;
sheepBody.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);`
The way I understand it, what I need to do is to alter X and Z-axis for a navmesh but not the Y. If you know of a better way I am open. Cheerio!!
Very nice! Maybe just put the 0.15f in a const to play with smoothness, but really nice simple code.
– MattThomSA