Translate in the direction of a point?

So if I have an NPC that needs to travel from point A to point B, and Point A is equal to 0,0, while Point B is equal to 10,50, then how do I get the NPC to go in the direction of point B, rather than go up ten and to the right fifty? I’m sure this is really simple, but my brain is not working right now and I usually just turn the NPC in the direction of its destination and use Transform.forward.

Hey, Unity has a usefull Gamekit where you could add nodes (“Waypoints”) to which your character should move. You can just add nodes if you want more waypoints or a pattern your character should move. In their tutorial they are using a platform but I think that makes no difference for your use.

To the GameKit


Or if you want only a script for your NPC to move between points you could use this script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class MoveNPC : MonoBehaviour
     public GameObject npc;
     public float moveSpeed;
     public Transform currentPoint;
     public Transform [] points;
     public int pointSelection;

     // Use this for initalization
     void Start()
         currentPoint = points [pointSelection];

     void Update()
         npc.transform.position = Vector3.MoveTowards (npc.transform.position, currentPoint.position, Time.deltaTime * moveSpeed);
         if (npc.transform.position == currentPoint.position)

             if (pointSelection == points.Length)
                     pointSelection = 0;

             currentPoint = points[pointSelection];

Now you just add childs to your NPC for each waypoint you want and add it to the points array.

Best regards, TheIcaruz