Zid Lyx
Zid Lyx

Reputation: 129

Unity rotation on hills

Hello im not that new to unity but i want to achive this : enter image description here

I have no idea how many people say ik but its too complex and some say with Quaternion but they dont explain how shoud i do it so if someone has a idea please share thank you . Im using A* pathfinding and using the example AI they have i tried using AIlerp that does what i want but it has alot of bugs :)

Upvotes: 1

Views: 166

Answers (1)

Iggy
Iggy

Reputation: 4888

You need to get the surface normal and apply it to the object. First find the vector that goes from point A to point B, rotate it by 90 degrees and finally normalize it.

Here's some pseudo code:

Vector3 pointA = new Vector3(x,y,z);
Vector3 pointB = new Vector3(x,y,z);

Vector3 dir = pointB - pointA;
Vector3 normal = new Vector3(-dir.y, dir.x).normalized;

object.transform.up = normal;

Upvotes: 2

Related Questions