Vector3s along ray?

Say I wanted to get a series of Vector3s along a ray for custom pathfinding. Each point would be a “waypoint” my NPC follows. How would I do that? Could I subtract the start and end positions incrementally or something? Here’s a picture of what I want if that helps:

Thanks!

1 Like

I’m not sure specifically what you’re looking for, so here’s a couple options:

If you have a start, an end, and a percentage along you want it to be, you can use Vector3:Lerp(OtherVector3, alpha). Alpha is the percentage of the way towards the end it is, so half would be 0.5, a quarter would be 0.25, etc.

If you have a ray and a number of studs you want to be along it, you can get the ray’s .Unit vector and multiply it by however many studs along it you want to go.

If neither of those work, can you be a bit clearer on what information you have (you said a ray, but the image shows an end and a start) and what exactly you’re looking for? (e.g. a specific point x studs along it? a specific point x% of the way down?)

5 Likes

A specific point x% of the way down is what I’m looking for. I think your first suggestion will work. I’ll try it out— thanks!

2 Likes