How would I detect if a part is moving in a curved path?

I currently have a part that moves along a set of nodes/waypoints and can rotate freely. I want to be able to detect whether the part is moving in a curve or a straight line, and if possible detect how sharp the curve/turn is. Since the part can rotate freely I can’t use any information about where the part is facing, ex. LookVector. How would I achieve this? Any help is appreciated.

3 Likes

You could try finding the orientation of the part and if it’s 0 on any two axes, then it would be moving straight.

2 Likes

Well, if you know the information about the nodes/waypoints, and the part is moving via CFraming along a spline, you could try getting the part’s position along the spline or where it is between two nodes, then test if nodes are linear with each other. So, check the two nodes ahead and the one behind and see if all three are inline with each other. If not, then you can try calculating an angle. You could do the same with the nodes on the other side of the part, and comparing the part’s position between the next and previous node to control between which angle it should bias towards?

1 Like

The part is being moved using forces and it isn’t always centered on the path

1 Like

You would have to use some trigonometry to calculate the continuous (or over a set period) offset between the two movement vectors. Then find the normals to these vectors and find the intersection point between these two normals (i.e. the center point if circular). If the intersection of the two normals are approximate then they have followed a circular path. Then using some sort of tolerance you can detect if the movement is as close to circular as you would like, or a curved path favouring either of the vectors dimensions. For this you could just triangulate the offset between consecutive intersection points.

1 Like

By movement vectors you mean node positions?

to know if it is moving in a straight line you must check if the speeds at x, y and z are constant. If they are, then it is moving in a straight line.
To find out how sharp the curve is you can calculate the curvature. These are discrete derivatives, so you need to know a lot of math.
I can’t think of anything simpler.

1 Like

You could use a while loop to take samples of the position of the part.

CurrentPosition
PreviousPosition
OldestPosition

Calculate the angle at PreviousPosition between CurrentPosition and OldestPosition.

I can’t use the velocity for this unless it’s the direction of the velocity

all baseparts have AssemblyLinearVelocity.

Yes, the start and end points (sampled over some set frequency).

1 Like

What I mean is that the part is rotating freely and there is also acceleration involved, so what you suggested would not work

Touché!

but the velocity can be calculated from the current and previous position.

currentVelocity = (currentPocition - previousPosition)/dt

as for the acceleration, if it moves in a straight line, the speed increase is also proportional for x, y and z. But it sounds like it is not so easy to implement.

good luck.