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.
You could try finding the orientation of the part and if it’s 0
on any two axes, then it would be moving straight.
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?
The part is being moved using forces and it isn’t always centered on the path
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.
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.
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).
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.