Animate object along a set of xy coordinates?

Hi, I’m new to Unity so really just looking for a starting point for this. Say I have a set of real-world xy coordinates in a csv file at 1-second intervals. They represent a person’s movement in a set space over time. I want to import these and use them to animate an object (eventually a humanoid character, but just a simple sphere/cube to begin with) along the path that the coordinates against time represents. How would I go about doing that?

First thoughts are:

  1. Would need to translate the real-world coordinates to the Unity Scene
  2. Would need to create a path through all the coordinates
  3. Maybe each coordinate should be a waypoint?
  4. Then animate the object along the path

Any good tips for how to start this? Thanks in advance!

Do you need to make a smooth curve connecting these points? Or is it fine if it just goes in a straight line from point to point?

In the former case, you probably should just get an existing asset, maybe something like this.

In the latter case, it’s pretty easy to do it yourself. Just keep track of which index you’re moving towards, and use code like this in Update:

transform.position = Vector3.MoveTowards(transform.position, waypoints[nextTargetIdx], speed * Time.deltaTime);

where speed is a property that controls how fast it moves, and nextTargetIdx is the index into your waypoints array (of type Vector3D). When transform.position == waypoints[nextTargetIdx], increment nextTargetIdx.

Hey, thanks for replying. It would need to make a smooth curve, so I will definitely look into Curvy, thanks for the link.