How do I figure out which direction a part is relative to another part?

I’m trying to make an animal AI system that when the player gets too close to the animal it runs away. However, I am not sure how to figure out which direction the players HumanoidRootPart is relative to the animals HumanoidRootPart so the animal knows which direction to run.

I’ve tried to search about my problem, but all I find is people asking how to find the lookVector of the HumanoidRootPart, which wouldn’t help me as the player could face backwards and have the animal run towards them instead.

Edits: accidentally deleted the topic lmao so I had to restore it

The direction vector from position A to position B is just B - A.

It’s length is the distance.

If you want it to be one stud long you can use (B - A).Unit

5 Likes

Great explanation. Thanks a lot!